Module: SimpleUserAuth::Model::ClassMethods
- Defined in:
- lib/simple_user_auth.rb
Instance Method Summary collapse
-
#authenticate(search, submitted_password, args = {}) ⇒ Object
Finds the user in the database by the authenticator and verifys them against the submitted password, takes an optional :find_by to override authenticate_by e.g.
-
#authenticate_by(authenticator) ⇒ Object
Select the database field you want to find the user by with when you use the authenticate method e.g.
-
#authenticate_with_salt(id, salt) ⇒ Object
Finds a user by a given id and authenticates them based on the salt stored in a cookie.
Instance Method Details
#authenticate(search, submitted_password, args = {}) ⇒ Object
Finds the user in the database by the authenticator and verifys them against the submitted password, takes an optional :find_by to override authenticate_by e.g. User.authenticate(params[:email], params[:password]) e.g. User.authenticate(params[:phone_number], params[:password], :find_by => :phone)
54 55 56 57 58 |
# File 'lib/simple_user_auth.rb', line 54 def authenticate(search, submitted_password, args = {}) user = find(:first, :conditions => ["#{args[:find_by] || authenticator} = ?", search]) return nil if user.nil? return user if user.has_password?(submitted_password) end |
#authenticate_by(authenticator) ⇒ Object
Select the database field you want to find the user by with when you use the authenticate method e.g. authenticate_by(:email)
47 48 49 |
# File 'lib/simple_user_auth.rb', line 47 def authenticate_by(authenticator) self.authenticator = authenticator end |
#authenticate_with_salt(id, salt) ⇒ Object
Finds a user by a given id and authenticates them based on the salt stored in a cookie.
61 62 63 64 |
# File 'lib/simple_user_auth.rb', line 61 def authenticate_with_salt(id, salt) user = find_by_id(id) (user && user.salt == salt) ? user : nil end |