Module: MongoMapper::Plugins::PasswordAuthentication::InstanceMethods

Defined in:
lib/rad/mongo_mapper/acts_as/authenticated_by_password.rb

Instance Method Summary collapse

Instance Method Details

#authenticated_by_password?(password) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/rad/mongo_mapper/acts_as/authenticated_by_password.rb', line 10

def authenticated_by_password? password
  return false if crypted_password.blank? or password.blank?
  self.crypted_password == self.class.encrypt_password(password, salt)
end

#password=(password) ⇒ Object

def update_password password, confirmation

self.password, self.password_confirmation = password, confirmation
encrypt_password

end

def generate_secure_token!

self.secure_token = AuthStrategy.generate_token
self.secure_token_expires_at = AuthStrategy::SECURE_TOKEN_EXPIRATION.from_now

end

def clear_secure_token!

self.secure_token = nil
self.secure_token_expires_at = nil

end

def forgot_password

generate_secure_token!
UserStatusMailer.deliver_forgot_password self

end



52
53
54
55
# File 'lib/rad/mongo_mapper/acts_as/authenticated_by_password.rb', line 52

def password= password
  @password = password
  encrypt_password!
end

#update_password(password, password_confirmation, old_password) ⇒ Object

def reset_password password, password_confirmation

self.password, self.password_confirmation = password, password_confirmation
self.secure_token = nil

end



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rad/mongo_mapper/acts_as/authenticated_by_password.rb', line 20

def update_password password, password_confirmation, old_password
  if crypted_password.blank?
    self.password, self.password_confirmation = password, password_confirmation
  elsif authenticated_by_password? old_password
    self.password, self.password_confirmation = password, password_confirmation
    true
  else
    errors.add :base, t(:invalid_old_password)
    false
  end
end