Module: Authlogic::ActsAsAuthentic::PersistenceToken::Methods

Defined in:
lib/authlogic/acts_as_authentic/persistence_token.rb

Overview

Methods for the persistence token.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/authlogic/acts_as_authentic/persistence_token.rb', line 16

def self.included(klass)
  klass.class_eval do
    extend ClassMethods
    include InstanceMethods

    # If the table does not have a password column, then
    # `after_password_set` etc. will not be defined. See
    # `Authlogic::ActsAsAuthentic::Password::Callbacks.included`
    if respond_to?(:after_password_set) && respond_to?(:after_password_verification)
      after_password_set :reset_persistence_token
      after_password_verification :reset_persistence_token!, if: :reset_persistence_token?
    end

    validates_presence_of :persistence_token
    validates_uniqueness_of :persistence_token, case_sensitive: true,
                                                if: :will_save_change_to_persistence_token?

    before_validation :reset_persistence_token, if: :reset_persistence_token?
  end
end