Class: User
- Inherits:
-
Party
- Object
- ActiveRecord::Base
- Party
- User
show all
- Defined in:
- app/models/user.rb
Overview
this model expects a certain database layout and its based on the name/login pattern. class User < ActiveRecord::Base
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Party
#current_speed, #icon, #to_sym
Constructor Details
#initialize(attributes = nil) ⇒ User
Returns a new instance of User.
44
45
46
47
|
# File 'app/models/user.rb', line 44
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.
16
17
18
|
# File 'app/models/user.rb', line 16
def password_needs_confirmation
@password_needs_confirmation
end
|
Class Method Details
.authenticate(login, pass) ⇒ Object
53
54
55
56
57
|
# File 'app/models/user.rb', line 53
def self.authenticate(login, pass)
u = find(:first, :conditions => ["login = ? AND verified = ? AND deleted = ?", login, true, false])
return nil if u.nil?
find(:first, :conditions => ["login = ? AND salted_password = ? AND verified = ?", login, salted_password(u.salt, hashed(pass)), true])
end
|
.authenticate_by_token(id, token) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/models/user.rb', line 59
def self.authenticate_by_token(id, token)
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
|
.token_lifetime ⇒ Object
97
98
99
|
# File 'app/models/user.rb', line 97
def self.token_lifetime
UserSystem::CONFIG[:security_token_life_hours] * 60 * 60
end
|
Instance Method Details
#change_password(pass, confirm = nil) ⇒ Object
91
92
93
94
95
|
# File 'app/models/user.rb', line 91
def change_password(pass, confirm = nil)
self.password = pass
self.password_confirmation = confirm.nil? ? pass : confirm
@password_needs_confirmation = true
end
|
#controller ⇒ Object
49
50
51
|
# File 'app/models/user.rb', line 49
def controller
self.class.name.downcase
end
|
#generate_security_token ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'app/models/user.rb', line 82
def generate_security_token
if token_stale?
token = new_security_token
return token
else
return self.security_token
end
end
|
#includes?(user) ⇒ Boolean
105
106
107
|
# File 'app/models/user.rb', line 105
def includes?(user)
return user == self
end
|
#name ⇒ Object
101
102
103
|
# File 'app/models/user.rb', line 101
def name
[first_name, last_name].compact.join(' ')
end
|
#token_expired? ⇒ Boolean
74
75
76
|
# File 'app/models/user.rb', line 74
def token_expired?
self.security_token.nil? or self.token_expiry.nil? or (Clock.now > self.token_expiry)
end
|
#token_stale? ⇒ Boolean
78
79
80
|
# File 'app/models/user.rb', line 78
def token_stale?
token_expired? or Clock.now.to_i >= (self.token_expiry.to_i - self.class.token_lifetime / 2)
end
|
#users ⇒ Object
109
110
111
|
# File 'app/models/user.rb', line 109
def users
[self]
end
|