Module: StupidAuth::Model::ClassMethods

Defined in:
lib/stupid_auth/model.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(login, provided_password = nil) ⇒ Object

Search the login_field for the given value and attempt to authenticate a found user with the given password set the logged in at timestamp



30
31
32
33
34
35
# File 'lib/stupid_auth/model.rb', line 30

def authenticate , provided_password = nil
  user = where("upper(#{  }) like ?", .upcase).first
  return nil unless user.present? and user.authenticated_by? provided_password
  user.send :set_logged_in_at!
  user
end

#login_with(field) ⇒ Object

Set the field name to use for authentication Accepts a string or a symbol of a property name



22
23
24
25
# File 'lib/stupid_auth/model.rb', line 22

def  field
  field = field.is_a?(Symbol) ? field : field.fieldify.to_sym
  new.respond_to?(field) ? @login_field = field : raise("#{ name } does not respond to #{ field.inspect }")
end