Module: Shoppy::Concerns::Models::ApiTokenAuthenticatable
- Extended by:
- ActiveSupport::Concern
- Included in:
- User
- Defined in:
- app/models/shoppy/concerns/models/api_token_authenticatable.rb
Instance Method Summary collapse
- #api_token_expired? ⇒ Boolean
- #generate_api_token ⇒ Object
- #invalidate_api_token ⇒ Object
- #valid_api_token? ⇒ Boolean
Instance Method Details
#api_token_expired? ⇒ Boolean
11 12 13 |
# File 'app/models/shoppy/concerns/models/api_token_authenticatable.rb', line 11 def api_token_expired? DateTime.now >= self.api_token_expires_at end |
#generate_api_token ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/models/shoppy/concerns/models/api_token_authenticatable.rb', line 20 def generate_api_token begin self.api_token = SecureRandom.hex end while self.class.exists?(api_token: api_token) self.api_token_expires_at = DateTime.now + 1.day self.api_token_active = true self end |
#invalidate_api_token ⇒ Object
29 30 31 32 33 |
# File 'app/models/shoppy/concerns/models/api_token_authenticatable.rb', line 29 def invalidate_api_token self.api_token = "" self.api_token_expires_at = Time.now self.api_token_active = false end |
#valid_api_token? ⇒ Boolean
15 16 17 |
# File 'app/models/shoppy/concerns/models/api_token_authenticatable.rb', line 15 def valid_api_token? self.api_token_active && !self.api_token_expired? end |