Module: SimpleUserAuth::Model::ClassMethods

Defined in:
lib/simple_user_auth.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) authenticate(search, submitted_password, args = {})

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, , args = {})
  user = find(:first, :conditions => ["#{args[:find_by] || authenticator} = ?", search])
  return nil  if user.nil?
  return user if user.has_password?()
end

- (Object) authenticate_by(authenticator)

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

- (Object) authenticate_with_salt(id, salt)

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