Module: SimpleAuth::Orm::Base::ClassMethods
- Defined in:
- lib/simple_auth/orm/base.rb
Instance Method Summary collapse
-
#authenticate(credential, password) ⇒ Object
Receive a credential and a password and try to authenticate the specified user.
-
#find_by_credential(credential) ⇒ Object
Find user by its credential.
-
#find_by_credential!(credential) ⇒ Object
Find user by its credential.
Instance Method Details
#authenticate(credential, password) ⇒ Object
Receive a credential and a password and try to authenticate the specified user. If the credential is valid, then an user is returned; otherwise nil is returned.
User.authenticate "johndoe", "test"
User.authenticate "[email protected]", "test"
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/simple_auth/orm/base.rb', line 63 def authenticate(credential, password) record = find_by_credential(credential) # If no record has been found return nil unless record # Compare password return nil unless record.password_hash == SimpleAuth::Config.crypter.call(password, record.password_salt) # Yay! Everything matched so return record. record end |
#find_by_credential(credential) ⇒ Object
Find user by its credential.
User.find_by_credential "[email protected]" # using e-mail
User.find_by_credential "john" # using username
44 45 46 |
# File 'lib/simple_auth/orm/base.rb', line 44 def find_by_credential(credential) raise SimpleAuth::AbstractMethodError end |
#find_by_credential!(credential) ⇒ Object
Find user by its credential. If no user is found, raise SimpleAuth::RecordNotFound exception.
User.find_by_credential! "[email protected]"
53 54 55 |
# File 'lib/simple_auth/orm/base.rb', line 53 def find_by_credential!(credential) raise SimpleAuth::AbstractMethodError end |