Module: UserTemplates::PasswordResetToken

Defined in:
app/user_templates/lib/password_reset_token.rb

Class Method Summary collapse

Class Method Details

.for_user(user_id, time_offset = 0) ⇒ Object



5
6
7
8
9
10
# File 'app/user_templates/lib/password_reset_token.rb', line 5

def self.for_user(user_id, time_offset=0)
  # Get a token with the hour as part of the hash.
  time_num = time_offset.hours.ago.beginning_of_hour.to_i

  Digest::SHA256.hexdigest("#{user_id}||#{Volt.config.app_secret}||#{time_num}")
end

.valid_token_for_user?(user_id, token) ⇒ Boolean

Checks for the current hour or the previous for the valid token

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
# File 'app/user_templates/lib/password_reset_token.rb', line 13

def self.valid_token_for_user?(user_id, token)
  if for_user(user_id, 0) == token
    true
  elsif for_user(user_id, 1) == token
    true
  else
    false
  end
end