Class: QuoVadis::Token

Inherits:
Object
  • Object
show all
Extended by:
Hmacable
Defined in:
app/models/quo_vadis/token.rb

Direct Known Subclasses

AccountConfirmationToken, PasswordResetToken

Class Method Summary collapse

Methods included from Hmacable

compute_hmac, timing_safe_eql?

Class Method Details

.find_account(token) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/quo_vadis/token.rb', line 15

def (token)
  provided_public_data, provided_hmac = token.split '--'
  id, expires_at = provided_public_data.split '-'
   = Account.find id
  data = data_for_hmac provided_public_data, 
  actual_hmac = compute_hmac data
  return nil unless timing_safe_eql? provided_hmac, actual_hmac
  return nil if expires_at.to_i < Time.current.to_i
  
rescue
  nil
end

.generate(account) ⇒ Object



9
10
11
12
13
# File 'app/models/quo_vadis/token.rb', line 9

def generate()
  public_data = "#{.id}-#{expires_at}"
  data = data_for_hmac public_data, 
  "#{public_data}--#{compute_hmac(data)}"
end