discourse/lib/email_backup_token.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

31 lines
495 B
Ruby

# frozen_string_literal: true
class EmailBackupToken
def self.key(user_id)
"email-backup-token:#{user_id}"
end
def self.generate
SecureRandom.hex
end
def self.set(user_id)
token = self.generate
$redis.setex self.key(user_id), 1.day.to_i, token
token
end
def self.get(user_id)
$redis.get self.key(user_id)
end
def self.del(user_id)
$redis.del self.key(user_id)
end
def self.compare(user_id, token)
token == self.get(user_id)
end
end