Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/user.rb
Instance Attribute Summary collapse
Class Method Summary collapse
- .authenticate(login_or_email, password) ⇒ Object
- .unprotected_attributes ⇒ Object
- .unprotected_attributes=(array) ⇒ Object
Instance Method Summary collapse
- #authenticated?(password) ⇒ Boolean
- #confirm_password? ⇒ Boolean
- #forget_me ⇒ Object
- #has_role?(role) ⇒ Boolean
- #remember_me ⇒ Object
- #sha1(phrase) ⇒ Object
Instance Attribute Details
#confirm_password ⇒ Object
59 60 61 |
# File 'app/models/user.rb', line 59 def confirm_password @confirm_password = true end |
Class Method Details
.authenticate(login_or_email, password) ⇒ Object
50 51 52 53 |
# File 'app/models/user.rb', line 50 def self.authenticate(login_or_email, password) user = find(:first, :conditions => ["login = ? OR email = ?", login_or_email, login_or_email]) user if user && user.authenticated?(password) end |
.unprotected_attributes ⇒ Object
33 34 35 |
# File 'app/models/user.rb', line 33 def unprotected_attributes @unprotected_attributes ||= [:name, :email, :login, :password, :password_confirmation, :locale] end |
.unprotected_attributes=(array) ⇒ Object
37 38 39 |
# File 'app/models/user.rb', line 37 def unprotected_attributes=(array) @unprotected_attributes = array.map{|att| att.to_sym } end |
Instance Method Details
#authenticated?(password) ⇒ Boolean
55 56 57 |
# File 'app/models/user.rb', line 55 def authenticated?(password) self.password == sha1(password) end |
#confirm_password? ⇒ Boolean
63 64 65 |
# File 'app/models/user.rb', line 63 def confirm_password? @confirm_password end |
#forget_me ⇒ Object
71 72 73 |
# File 'app/models/user.rb', line 71 def forget_me update_attribute(:session_token, nil) end |
#has_role?(role) ⇒ Boolean
42 43 44 |
# File 'app/models/user.rb', line 42 def has_role?(role) respond_to?("#{role}?") && send("#{role}?") end |
#remember_me ⇒ Object
67 68 69 |
# File 'app/models/user.rb', line 67 def remember_me update_attribute(:session_token, sha1(Time.now + Radiant::Config['session_timeout'].to_i)) unless self.session_token? end |
#sha1(phrase) ⇒ Object
46 47 48 |
# File 'app/models/user.rb', line 46 def sha1(phrase) Digest::SHA1.hexdigest("--#{salt}--#{phrase}--") end |