mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
More more logic to Authenticatable.
This commit is contained in:
parent
9291ab55b8
commit
3135487931
3 changed files with 26 additions and 28 deletions
|
@ -77,7 +77,7 @@ module Devise
|
||||||
|
|
||||||
# Return modules for the mapping.
|
# Return modules for the mapping.
|
||||||
def modules
|
def modules
|
||||||
@modules ||= to.devise_modules
|
@modules ||= to.respond_to?(:devise_modules) ? to.devise_modules : []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Gives the class the mapping points to.
|
# Gives the class the mapping points to.
|
||||||
|
|
|
@ -45,7 +45,6 @@ module Devise
|
||||||
# for a complete description on those values.
|
# for a complete description on those values.
|
||||||
#
|
#
|
||||||
def devise(*modules)
|
def devise(*modules)
|
||||||
define_devise_class_attributes!
|
|
||||||
include Devise::Models::Authenticatable
|
include Devise::Models::Authenticatable
|
||||||
options = modules.extract_options!
|
options = modules.extract_options!
|
||||||
|
|
||||||
|
@ -75,32 +74,6 @@ module Devise
|
||||||
def devise_modules_hook!
|
def devise_modules_hook!
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find an initialize a record setting an error if it can't be found.
|
|
||||||
def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc:
|
|
||||||
if value.present?
|
|
||||||
conditions = { attribute => value }
|
|
||||||
record = find(:first, :conditions => conditions)
|
|
||||||
end
|
|
||||||
|
|
||||||
unless record
|
|
||||||
record = new
|
|
||||||
if value.present?
|
|
||||||
record.send(:"#{attribute}=", value)
|
|
||||||
else
|
|
||||||
error = :blank
|
|
||||||
end
|
|
||||||
record.errors.add(attribute, error)
|
|
||||||
end
|
|
||||||
|
|
||||||
record
|
|
||||||
end
|
|
||||||
|
|
||||||
def define_devise_class_attributes! #:nodoc:
|
|
||||||
return if respond_to?(:devise_modules)
|
|
||||||
class_attribute :devise_modules, :instance_writer => false
|
|
||||||
self.devise_modules = []
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,11 @@ module Devise
|
||||||
module Authenticatable
|
module Authenticatable
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
class_attribute :devise_modules, :instance_writer => false
|
||||||
|
self.devise_modules ||= []
|
||||||
|
end
|
||||||
|
|
||||||
# Check if the current object is valid for authentication. This method and find_for_authentication
|
# Check if the current object is valid for authentication. This method and find_for_authentication
|
||||||
# are the methods used in a Warden::Strategy to check if a model should be signed in or not.
|
# are the methods used in a Warden::Strategy to check if a model should be signed in or not.
|
||||||
#
|
#
|
||||||
|
@ -86,6 +91,26 @@ module Devise
|
||||||
def find_for_authentication(conditions)
|
def find_for_authentication(conditions)
|
||||||
find(:first, :conditions => conditions)
|
find(:first, :conditions => conditions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Find an initialize a record setting an error if it can't be found.
|
||||||
|
def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc:
|
||||||
|
if value.present?
|
||||||
|
conditions = { attribute => value }
|
||||||
|
record = find(:first, :conditions => conditions)
|
||||||
|
end
|
||||||
|
|
||||||
|
unless record
|
||||||
|
record = new
|
||||||
|
if value.present?
|
||||||
|
record.send(:"#{attribute}=", value)
|
||||||
|
else
|
||||||
|
error = :blank
|
||||||
|
end
|
||||||
|
record.errors.add(attribute, error)
|
||||||
|
end
|
||||||
|
|
||||||
|
record
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue