Module: Devise::Models::Authenticatable

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise/models/authenticatable.rb

Overview

Authenticable module. Holds common settings for authentication.

Configuration:

You can overwrite configuration values by setting in globally in Devise, using devise method or overwriting the respective instance method.

authentication_keys: parameters used for authentication. By default [:email].

http_authenticatable: if this model allows http authentication. By default true.
It also accepts an array specifying the strategies that should allow http.

params_authenticatable: if this model allows authentication through request params. By default true.
It also accepts an array specifying the strategies that should allow params authentication.

Active?

Before authenticating an user and in each request, Devise checks if your model is active by calling model.active?. This method is overwriten by other devise modules. For instance, :confirmable overwrites .active? 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?
  super && special_condition_is_valid?
end

Whenever active? returns false, Devise asks the reason why your model is inactive using the inactive_message method. You can overwrite it as well:

def inactive_message
  special_condition_is_valid? ? super : :special_condition_is_not_valid
end

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/devise/models/authenticatable.rb', line 61

def active?
  true
end

#inactive_messageObject



65
66
67
# File 'lib/devise/models/authenticatable.rb', line 65

def inactive_message
  :inactive
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? and inactive_message instead.

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/devise/models/authenticatable.rb', line 53

def valid_for_authentication?
  if active?
    block_given? ? yield : true
  else
    inactive_message
  end
end