Module: Cms::Authentication::Model::InstanceMethods
- Defined in:
- lib/cms/authentication/model.rb
Instance Method Summary collapse
- #authenticated?(password) ⇒ Boolean
-
#change_password(new_password) ⇒ Object
Method to make it easy to change a user’s password from the console, not used in the app.
-
#encrypt(password) ⇒ Object
Encrypts the password with the user salt.
-
#encrypt_password ⇒ Object
before filter.
-
#forget_me ⇒ Object
Deletes the server-side record of the authentication token.
- #password_required? ⇒ Boolean
-
#refresh_token ⇒ Object
refresh token (keeping same expires_at) if it exists.
-
#remember_me ⇒ Object
These create and unset the fields required for remembering users between browser closes.
- #remember_me_for(time) ⇒ Object
- #remember_me_until(time) ⇒ Object
- #remember_token? ⇒ Boolean
Instance Method Details
#authenticated?(password) ⇒ Boolean
60 61 62 |
# File 'lib/cms/authentication/model.rb', line 60 def authenticated?(password) crypted_password == encrypt(password) end |
#change_password(new_password) ⇒ Object
Method to make it easy to change a user’s password from the console, not used in the app
51 52 53 |
# File 'lib/cms/authentication/model.rb', line 51 def change_password(new_password) update_attributes(:password => new_password, :password_confirmation => new_password) end |
#encrypt(password) ⇒ Object
Encrypts the password with the user salt
56 57 58 |
# File 'lib/cms/authentication/model.rb', line 56 def encrypt(password) self.class.password_digest(password, salt) end |
#encrypt_password ⇒ Object
before filter
65 66 67 68 69 |
# File 'lib/cms/authentication/model.rb', line 65 def encrypt_password return if password.blank? self.salt = self.class.make_token if new_record? self.crypted_password = encrypt(password) end |
#forget_me ⇒ Object
Deletes the server-side record of the authentication token. The client-side (browser cookie) and server-side (this remember_token) must always be deleted together.
108 109 110 111 112 |
# File 'lib/cms/authentication/model.rb', line 108 def forget_me self.remember_token_expires_at = nil self.remember_token = nil save end |
#password_required? ⇒ Boolean
71 72 73 |
# File 'lib/cms/authentication/model.rb', line 71 def password_required? crypted_password.blank? || !password.blank? end |
#refresh_token ⇒ Object
refresh token (keeping same expires_at) if it exists
96 97 98 99 100 101 |
# File 'lib/cms/authentication/model.rb', line 96 def refresh_token if remember_token? self.remember_token = self.class.make_token save end end |
#remember_me ⇒ Object
These create and unset the fields required for remembering users between browser closes
81 82 83 |
# File 'lib/cms/authentication/model.rb', line 81 def remember_me remember_me_for 2.weeks end |
#remember_me_for(time) ⇒ Object
85 86 87 |
# File 'lib/cms/authentication/model.rb', line 85 def remember_me_for(time) remember_me_until time.from_now.utc end |
#remember_me_until(time) ⇒ Object
89 90 91 92 93 |
# File 'lib/cms/authentication/model.rb', line 89 def remember_me_until(time) self.remember_token_expires_at = time self.remember_token = self.class.make_token save end |
#remember_token? ⇒ Boolean
75 76 77 78 |
# File 'lib/cms/authentication/model.rb', line 75 def remember_token? (!remember_token.blank?) && remember_token_expires_at && (Time.now.utc < remember_token_expires_at.utc) end |