Class: Workarea::User::AuthenticationToken

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument, UrlToken
Defined in:
app/models/workarea/user/authentication_token.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authenticate(token, options = {}) ⇒ Object



15
16
17
18
19
# File 'app/models/workarea/user/authentication_token.rb', line 15

def self.authenticate(token, options = {})
  result = where(token: token).first
  return if result.try(:expired?)
  result
end

.expires_atObject



11
12
13
# File 'app/models/workarea/user/authentication_token.rb', line 11

def self.expires_at
  Time.now + Workarea.config.authentication_token_expiration
end

.refresh!(token, options = {}) ⇒ Object



21
22
23
24
25
26
# File 'app/models/workarea/user/authentication_token.rb', line 21

def self.refresh!(token, options = {})
  result = where(token: token).first
  return if result.try(:expired?)
  return unless result.update_attribute(:expires_at, expires_at)
  result
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/workarea/user/authentication_token.rb', line 28

def expired?
  expires_at <= Time.now
end