Module: Devise::Models::TokenAuthenticatable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/metova/devise/models/token_authenticatable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #ensure_authentication_token! ⇒ Object
- #expire_token_in ⇒ Object
- #reset_authentication_token ⇒ Object
- #reset_authentication_token! ⇒ Object
- #token_expired? ⇒ Boolean
Class Method Details
.required_fields(klass) ⇒ Object
12 13 14 |
# File 'lib/metova/devise/models/token_authenticatable.rb', line 12 def self.required_fields(klass) [:authentication_token, :token_expires_at] end |
Instance Method Details
#ensure_authentication_token! ⇒ Object
29 30 31 |
# File 'lib/metova/devise/models/token_authenticatable.rb', line 29 def ensure_authentication_token! reset_authentication_token! if authentication_token.blank? || token_expired? end |
#expire_token_in ⇒ Object
37 38 39 |
# File 'lib/metova/devise/models/token_authenticatable.rb', line 37 def expire_token_in 14.days end |
#reset_authentication_token ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/metova/devise/models/token_authenticatable.rb', line 16 def reset_authentication_token self.authentication_token = loop do token = Devise.friendly_token break token unless self.class.exists?(authentication_token: token) end self.token_expires_at = Time.current + expire_token_in end |
#reset_authentication_token! ⇒ Object
24 25 26 27 |
# File 'lib/metova/devise/models/token_authenticatable.rb', line 24 def reset_authentication_token! reset_authentication_token save validate: false end |
#token_expired? ⇒ Boolean
33 34 35 |
# File 'lib/metova/devise/models/token_authenticatable.rb', line 33 def token_expired? token_expires_at.nil? || token_expires_at.past? end |