module Authlogic::ActsAsAuthentic::PersistenceToken::Methods

Methods for the persistence token.

Public Class Methods

included(klass) click to toggle source
# 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