Commit 1def090dc48c94c2722a2f97f0a86f5a89acb6ee
1 parent
114c4651
Exists in
master
and in
29 other branches
ActionItem9: minor doc work
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@194 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
1 changed file
with
6 additions
and
1 deletions
Show diff stats
app/models/user.rb
@@ -41,10 +41,12 @@ class User < ActiveRecord::Base | @@ -41,10 +41,12 @@ class User < ActiveRecord::Base | ||
41 | self.class.encrypt(password, salt) | 41 | self.class.encrypt(password, salt) |
42 | end | 42 | end |
43 | 43 | ||
44 | + # returns +true+ if the +password+ is the correct one for the user | ||
44 | def authenticated?(password) | 45 | def authenticated?(password) |
45 | crypted_password == encrypt(password) | 46 | crypted_password == encrypt(password) |
46 | end | 47 | end |
47 | 48 | ||
49 | + # tells if the user has an authentication cookie | ||
48 | def remember_token? | 50 | def remember_token? |
49 | remember_token_expires_at && Time.now.utc < remember_token_expires_at | 51 | remember_token_expires_at && Time.now.utc < remember_token_expires_at |
50 | end | 52 | end |
@@ -56,6 +58,7 @@ class User < ActiveRecord::Base | @@ -56,6 +58,7 @@ class User < ActiveRecord::Base | ||
56 | save(false) | 58 | save(false) |
57 | end | 59 | end |
58 | 60 | ||
61 | + # throws the auth cookie away | ||
59 | def forget_me | 62 | def forget_me |
60 | self.remember_token_expires_at = nil | 63 | self.remember_token_expires_at = nil |
61 | self.remember_token = nil | 64 | self.remember_token = nil |
@@ -87,7 +90,9 @@ class User < ActiveRecord::Base | @@ -87,7 +90,9 @@ class User < ActiveRecord::Base | ||
87 | self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record? | 90 | self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record? |
88 | self.crypted_password = encrypt(password) | 91 | self.crypted_password = encrypt(password) |
89 | end | 92 | end |
90 | - | 93 | + |
94 | + # auxiliary method to test if a password must be supplied (i.e. returns | ||
95 | + # +true+ when creating an user without supplying a password) | ||
91 | def password_required? | 96 | def password_required? |
92 | crypted_password.blank? || !password.blank? | 97 | crypted_password.blank? || !password.blank? |
93 | end | 98 | end |