Class: User
Instance Attribute Summary collapse
-
#confirm_password ⇒ Object
writeonly
Sets the attribute confirm_password.
Class Method Summary collapse
- .authenticate(login, password) ⇒ Object
- .protected_attributes ⇒ Object
- .protected_attributes=(array) ⇒ Object
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #authenticated?(password) ⇒ Boolean
- #confirm_password? ⇒ Boolean
- #forget_me ⇒ Object
- #has_role?(role) ⇒ Boolean
- #remember_me ⇒ Object
- #sha1(phrase) ⇒ Object
Instance Attribute Details
#confirm_password=(value) ⇒ Object (writeonly)
Sets the attribute confirm_password
29 30 31 |
# File 'app/models/user.rb', line 29 def confirm_password=(value) @confirm_password = value end |
Class Method Details
.authenticate(login, password) ⇒ Object
48 49 50 51 |
# File 'app/models/user.rb', line 48 def self.authenticate(login, password) user = find_by_login(login) user if user && user.authenticated?(password) end |
.protected_attributes ⇒ Object
31 32 33 |
# File 'app/models/user.rb', line 31 def protected_attributes @protected_attributes ||= [:name, :email, :login, :password, :password_confirmation] end |
.protected_attributes=(array) ⇒ Object
35 36 37 |
# File 'app/models/user.rb', line 35 def protected_attributes=(array) @protected_attributes = array.map{|att| att.to_sym } end |
Instance Method Details
#after_initialize ⇒ Object
57 58 59 |
# File 'app/models/user.rb', line 57 def after_initialize @confirm_password = true end |
#authenticated?(password) ⇒ Boolean
53 54 55 |
# File 'app/models/user.rb', line 53 def authenticated?(password) self.password == sha1(password) end |
#confirm_password? ⇒ Boolean
61 62 63 |
# File 'app/models/user.rb', line 61 def confirm_password? @confirm_password end |
#forget_me ⇒ Object
69 70 71 |
# File 'app/models/user.rb', line 69 def forget_me update_attribute(:session_token, nil) end |
#has_role?(role) ⇒ Boolean
40 41 42 |
# File 'app/models/user.rb', line 40 def has_role?(role) respond_to?("#{role}?") && send("#{role}?") end |
#remember_me ⇒ Object
65 66 67 |
# File 'app/models/user.rb', line 65 def remember_me update_attribute(:session_token, sha1(Time.now + Radiant::Config['session_timeout'].to_i)) unless self.session_token? end |
#sha1(phrase) ⇒ Object
44 45 46 |
# File 'app/models/user.rb', line 44 def sha1(phrase) Digest::SHA1.hexdigest("--#{salt}--#{phrase}--") end |