Class: User
Overview
this model expects a certain database layout and its based on the name/login pattern. class User < ActiveRecord::Base
Instance Attribute Summary collapse
-
#password_needs_confirmation ⇒ Object
Returns the value of attribute password_needs_confirmation.
Class Method Summary collapse
Instance Method Summary collapse
- #change_password(pass, confirm = nil) ⇒ Object
- #controller ⇒ Object
- #generate_security_token ⇒ Object
- #includes?(user) ⇒ Boolean
-
#initialize(attributes = nil) ⇒ User
constructor
A new instance of User.
- #name ⇒ Object
- #token_expired? ⇒ Boolean
- #token_lifetime ⇒ Object
Methods inherited from Party
Constructor Details
#initialize(attributes = nil) ⇒ User
Returns a new instance of User.
40 41 42 43 |
# File 'app/models/user.rb', line 40 def initialize(attributes = nil) super @password_needs_confirmation = false end |
Instance Attribute Details
#password_needs_confirmation ⇒ Object
Returns the value of attribute password_needs_confirmation.
12 13 14 |
# File 'app/models/user.rb', line 12 def password_needs_confirmation @password_needs_confirmation end |
Class Method Details
.authenticate(login, pass) ⇒ Object
49 50 51 52 53 |
# File 'app/models/user.rb', line 49 def self.authenticate(login, pass) u = find(:first, :conditions => ["login = ? AND verified = TRUE AND deleted = FALSE", login]) return nil if u.nil? find(:first, :conditions => ["login = ? AND salted_password = ? AND verified = TRUE", login, salted_password(u.salt, hashed(pass))]) end |
.authenticate_by_token(id, token) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/user.rb', line 55 def self.authenticate_by_token(id, token) # Allow logins for deleted accounts, but only via this method (and # not the regular authenticate call) logger.info "Attempting authorization of #{id} with #{token}" u = find(:first, :conditions => ["id = ? AND security_token = ?", id, token]) if u logger.info "Authenticated by token: #{u.inspect}" else logger.info "Not authenticated" if u.nil? end return nil if (u.nil? or u.token_expired?) u.update_attribute :verified, true return u end |
Instance Method Details
#change_password(pass, confirm = nil) ⇒ Object
83 84 85 86 87 |
# File 'app/models/user.rb', line 83 def change_password(pass, confirm = nil) self.password = pass self.password_confirmation = confirm.nil? ? pass : confirm @password_needs_confirmation = true end |
#controller ⇒ Object
45 46 47 |
# File 'app/models/user.rb', line 45 def controller self.class.name.downcase end |
#generate_security_token ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/models/user.rb', line 74 def generate_security_token if self.security_token.nil? or self.token_expiry.nil? or (Clock.now.to_i + token_lifetime / 2) >= self.token_expiry.to_i token = new_security_token return token else return self.security_token end end |
#includes?(user) ⇒ Boolean
97 98 99 |
# File 'app/models/user.rb', line 97 def includes?(user) return user == self end |
#name ⇒ Object
93 94 95 |
# File 'app/models/user.rb', line 93 def name [first_name, last_name].compact.join(' ') end |
#token_expired? ⇒ Boolean
70 71 72 |
# File 'app/models/user.rb', line 70 def token_expired? self.security_token and self.token_expiry and (Clock.now > self.token_expiry) end |
#token_lifetime ⇒ Object
89 90 91 |
# File 'app/models/user.rb', line 89 def token_lifetime UserSystem::CONFIG[:security_token_life_hours] * 60 * 60 end |