Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/user.rb
Instance Attribute Summary collapse
-
#confirm_password ⇒ Object
writeonly
Sets the attribute confirm_password.
Class Method Summary collapse
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
28 29 30 |
# File 'app/models/user.rb', line 28 def confirm_password=(value) @confirm_password = value end |
Class Method Details
.authenticate(login_or_email, password) ⇒ Object
38 39 40 41 |
# File 'app/models/user.rb', line 38 def self.authenticate(login_or_email, password) user = where(["login = ? OR email = ?", login_or_email, login_or_email]).first user if user && user.authenticated?(password) end |
Instance Method Details
#after_initialize ⇒ Object
47 48 49 |
# File 'app/models/user.rb', line 47 def after_initialize @confirm_password = true end |
#authenticated?(password) ⇒ Boolean
43 44 45 |
# File 'app/models/user.rb', line 43 def authenticated?(password) self.password == sha1(password) end |
#confirm_password? ⇒ Boolean
51 52 53 |
# File 'app/models/user.rb', line 51 def confirm_password? @confirm_password end |
#forget_me ⇒ Object
59 60 61 |
# File 'app/models/user.rb', line 59 def forget_me update_attribute(:session_token, nil) end |
#has_role?(role) ⇒ Boolean
30 31 32 |
# File 'app/models/user.rb', line 30 def has_role?(role) respond_to?("#{role}?") && send("#{role}?") end |
#remember_me ⇒ Object
55 56 57 |
# File 'app/models/user.rb', line 55 def remember_me update_attribute(:session_token, sha1(Time.now + TrustyCms::Config['session_timeout'].to_i)) unless self.session_token? end |
#sha1(phrase) ⇒ Object
34 35 36 |
# File 'app/models/user.rb', line 34 def sha1(phrase) Digest::SHA1.hexdigest("--#{salt}--#{phrase}--") end |