Module: Devise::Models::Authenticatable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise/models/authenticatable.rb
Overview
Authenticatable module. Holds common settings for authentication.
Options
Authenticatable adds the following options to devise_for:
* +authentication_keys+: parameters used for authentication. By default [:email].
* +request_keys+: parameters from the request object used for authentication.
By a symbol (which should be a request method), it will automatically be
passed to find_for_authentication method and considered in your model lookup.
For instance, if you set :request_keys to [:subdomain], :subdomain will be considered
as key on authentication. This can also be a hash where the value is a boolean expliciting
if the value is required or not.
* +http_authenticatable+: if this model allows http authentication. By default true.
It also accepts an array the strategies that should allow http.
* +params_authenticatable+: if this model allows authentication through request params. By default true.
It also accepts an array the strategies that should allow params authentication.
* +skip_session_storage+: By default Devise will store the user in session.
You can skip storage for http and token auth by appending values to array:
:skip_session_storage => [:token_auth] or :skip_session_storage => [:http_auth, :token_auth],
by default is set to :skip_session_storage => [:http_auth].
active_for_authentication?
After authenticating a user and in each request, Devise checks if your model is active by calling model.active_for_authentication?. This method is overwriten by other devise modules. For instance, :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed.
You overwrite this method yourself, but if you do, don’t forget to call super:
def active_for_authentication?
super && special_condition_is_valid?
end
Whenever active_for_authentication? returns false, Devise asks the reason why your model is inactive using the inactive_message method. You can overwrite it as well:
def
special_condition_is_valid? ? super : :special_condition_is_not_valid
end
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- BLACKLIST_FOR_SERIALIZATION =
[:encrypted_password, :reset_password_token, :reset_password_sent_at, :remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip, :password_salt, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at, :authentication_token]
Instance Method Summary collapse
- #active_for_authentication? ⇒ Boolean
- #authenticatable_salt ⇒ Object
- #devise_mailer ⇒ Object
- #downcase_keys ⇒ Object
- #headers_for(name) ⇒ Object
- #inactive_message ⇒ Object
- #strip_whitespace ⇒ Object
-
#valid_for_authentication? ⇒ Boolean
Check if the current object is valid for authentication.
Instance Method Details
#active_for_authentication? ⇒ Boolean
77 78 79 |
# File 'lib/devise/models/authenticatable.rb', line 77 def active_for_authentication? true end |
#authenticatable_salt ⇒ Object
85 86 |
# File 'lib/devise/models/authenticatable.rb', line 85 def authenticatable_salt end |
#devise_mailer ⇒ Object
88 89 90 |
# File 'lib/devise/models/authenticatable.rb', line 88 def devise_mailer Devise.mailer end |
#downcase_keys ⇒ Object
96 97 98 |
# File 'lib/devise/models/authenticatable.rb', line 96 def downcase_keys (self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) } end |
#headers_for(name) ⇒ Object
92 93 94 |
# File 'lib/devise/models/authenticatable.rb', line 92 def headers_for(name) {} end |
#inactive_message ⇒ Object
81 82 83 |
# File 'lib/devise/models/authenticatable.rb', line 81 def :inactive end |
#strip_whitespace ⇒ Object
100 101 102 |
# File 'lib/devise/models/authenticatable.rb', line 100 def strip_whitespace (self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) } end |
#valid_for_authentication? ⇒ Boolean
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.
However, you should not overwrite this method, you should overwrite active_for_authentication? and inactive_message instead.
73 74 75 |
# File 'lib/devise/models/authenticatable.rb', line 73 def valid_for_authentication? block_given? ? yield : true end |