Module: ModelMixin::InstanceMethodsOnActivation
- Defined in:
- app/models/model_mixin.rb
Instance Method Summary collapse
-
#clear_token ⇒ Object
Clears the user’s timestamped token and saves the record.
-
#generate_token ⇒ Object
Generates a unique, timestamped token.
-
#generate_token! ⇒ Object
Generates a unique, timestamped token which can be used in URLs, and saves the record.
-
#has_matching_password?(plain_text_password) ⇒ Boolean
Returns true if the given
plain_text_password
is the user’s password, and false otherwise. -
#has_matching_salt?(salt) ⇒ Boolean
Returns true if the given
salt
is the user’s salt, and false otherwise. -
#password=(plain_text_password) ⇒ Object
:nodoc:.
-
#password_salt ⇒ Object
:nodoc:.
-
#should_authenticate? ⇒ Boolean
Override this in your model if you need to bypass the Quo Vadis validations.
Instance Method Details
#clear_token ⇒ Object
Clears the user’s timestamped token and saves the record. This is part of the forgotten-password workflow.
93 94 95 |
# File 'app/models/model_mixin.rb', line 93 def clear_token # :nodoc: update_attributes :token => nil, :token_created_at => nil end |
#generate_token ⇒ Object
Generates a unique, timestamped token.
77 78 79 80 81 82 |
# File 'app/models/model_mixin.rb', line 77 def generate_token # :nodoc: begin self.token = url_friendly_token end while self.class.exists?(:token => token) self.token_created_at = Time.now.utc end |
#generate_token! ⇒ Object
Generates a unique, timestamped token which can be used in URLs, and saves the record. This is part of the forgotten-password workflow.
86 87 88 89 |
# File 'app/models/model_mixin.rb', line 86 def generate_token! # :nodoc: generate_token save end |
#has_matching_password?(plain_text_password) ⇒ Boolean
Returns true if the given plain_text_password
is the user’s password, and false otherwise.
99 100 101 |
# File 'app/models/model_mixin.rb', line 99 def has_matching_password?(plain_text_password) # :nodoc: BCrypt::Password.new(password_digest) == plain_text_password end |
#has_matching_salt?(salt) ⇒ Boolean
Returns true if the given salt
is the user’s salt, and false otherwise.
105 106 107 |
# File 'app/models/model_mixin.rb', line 105 def has_matching_salt?(salt) # :nodoc: password_salt == salt end |
#password=(plain_text_password) ⇒ Object
:nodoc:
69 70 71 72 73 74 |
# File 'app/models/model_mixin.rb', line 69 def password=(plain_text_password) # :nodoc: @password = plain_text_password unless @password.blank? self.password_digest = BCrypt::Password.create plain_text_password end end |
#password_salt ⇒ Object
:nodoc:
109 110 111 |
# File 'app/models/model_mixin.rb', line 109 def password_salt # :nodoc: BCrypt::Password.new(password_digest).salt end |
#should_authenticate? ⇒ Boolean
Override this in your model if you need to bypass the Quo Vadis validations.
65 66 67 |
# File 'app/models/model_mixin.rb', line 65 def should_authenticate? true end |