Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Includes:
- AASM, Authentication, Authentication::ByCookieToken, Authentication::ByPassword
- Defined in:
- lib/branston/app/models/user.rb
Constant Summary collapse
- ROLES =
["admin", "developer", "customer"]
Class Method Summary collapse
-
.authenticate(login, password) ⇒ Object
Authenticates a user by their login name and unencrypted password.
Instance Method Summary collapse
Methods included from Authentication::ByCookieToken
Methods included from Authentication::ByPassword
Methods included from Authentication
Class Method Details
.authenticate(login, password) ⇒ Object
Authenticates a user by their login name and unencrypted password. Returns the user or nil.
uff. this is really an authorization, not authentication routine. We really need a Dispatch Chain here or something. This will also let us return a human error message.
84 85 86 87 88 |
# File 'lib/branston/app/models/user.rb', line 84 def self.authenticate(login, password) return nil if login.blank? || password.blank? u = find_in_state :first, :active, :conditions => {:login => login.downcase} u && u.authenticated?(password) ? u : nil end |
Instance Method Details
#email=(value) ⇒ Object
94 95 96 |
# File 'lib/branston/app/models/user.rb', line 94 def email=(value) write_attribute :email, (value ? value.downcase : nil) end |
#has_role?(role_name) ⇒ Boolean
74 75 76 |
# File 'lib/branston/app/models/user.rb', line 74 def has_role?(role_name) self.role == role_name end |
#login=(value) ⇒ Object
90 91 92 |
# File 'lib/branston/app/models/user.rb', line 90 def login=(value) write_attribute :login, (value ? value.downcase : nil) end |
#to_s ⇒ Object
98 99 100 |
# File 'lib/branston/app/models/user.rb', line 98 def to_s login end |