Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
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

Instance Method Summary collapse

Methods included from Authentication::ByCookieToken

included

Methods included from Authentication::ByPassword

included

Methods included from Authentication

included

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(, password)
  return nil if .blank? || password.blank?
  u = find_in_state :first, :active, :conditions => {: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

Returns:

  • (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_sObject



98
99
100
# File 'lib/branston/app/models/user.rb', line 98

def to_s
  
end