Module: Authlogic::ActsAsAuthentic::EmailToken::Methods::ClassMethods
- Defined in:
- lib/authlogic/acts_as_authentic/email_token.rb
Instance Method Summary collapse
-
#find_using_email_token(token, age = self.email_token_valid_for) ⇒ Object
Use this method to find a record with an email confirmation token.
-
#find_using_email_token!(token, age = self.email_token_valid_for) ⇒ Object
This method will raise
ActiveRecord::RecordNotFound
if no record is found.
Instance Method Details
#find_using_email_token(token, age = self.email_token_valid_for) ⇒ Object
Use this method to find a record with an email confirmation token. This method does 2 things for you:
-
It ignores blank tokens
-
It enforces the email_token_valid_for configuration option.
If you want to use a different timeout value, just pass it as the second parameter:
User.find_using_email_token(token, 1.hour)
This method is very similar to, and based heavily off of, Authlogic’s #find_using_perishable_token
method.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/authlogic/acts_as_authentic/email_token.rb', line 98 def find_using_email_token(token, age = self.email_token_valid_for) return if token.blank? age = age.to_i # Authlogic builds its SQL by hand, but I prefer Arel. The logic is the same. # No need to add an IS NOT NULL clause, because above, we return if the given # token is blank. t = arel_table conditions = t[:email_token].eq(token) if age > 0 conditions = conditions.and( t[:email_token_updated_at].gt(age.seconds.ago) ) end where(conditions).first end |
#find_using_email_token!(token, age = self.email_token_valid_for) ⇒ Object
This method will raise ActiveRecord::RecordNotFound
if no record is found.
117 118 119 |
# File 'lib/authlogic/acts_as_authentic/email_token.rb', line 117 def find_using_email_token!(token, age = self.email_token_valid_for) find_using_email_token(token, age) || raise(ActiveRecord::RecordNotFound) end |