Module: Auth::Behavior::Core::AuthenticatedModelMethods

Defined in:
lib/auth/behavior/core/authenticated_model_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 2

def self.included(base)
  base.instance_eval do
    delegate :persistence_token, :single_access_token, :perishable_token, :to => :password_model
  end
end

Instance Method Details

#after_saveObject



44
45
46
47
48
49
50
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 44

def after_save
  @new_password = nil
  # clear out old passwords so we're conforming to sparkly_config.password_history_length
  while passwords.length > sparkly_config.password_history_length
    passwords.shift.destroy
  end
end

#passwordObject



24
25
26
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 24

def password
  password_model.secret
end

#password=(value) ⇒ Object



28
29
30
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 28

def password=(value)
  new_password.secret = value
end

#password_changed?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 40

def password_changed?
  password_model.new_record? || password_model.secret_changed?
end

#password_confirmationObject



36
37
38
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 36

def password_confirmation
  password_model.secret_confirmation
end

#password_confirmation=(value) ⇒ Object



32
33
34
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 32

def password_confirmation=(value)
  new_password.secret_confirmation = value
end

#password_expired?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 8

def password_expired?
  passwords.empty? || passwords.last.created_at < sparkly_config.password_update_frequency.ago
end

#password_matches?(phrase) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 20

def password_matches?(phrase)
  password_model.matches?(phrase)
end

#password_modelObject



12
13
14
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 12

def password_model
  passwords.empty? || @new_password ? new_password : passwords.last
end

#password_required?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/auth/behavior/core/authenticated_model_methods.rb', line 16

def password_required?
  new_record? || passwords.empty? || passwords.last.secret.blank?
end