2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-01 23:26:18 +08:00
|
|
|
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
|
2019-12-03 17:05:53 +08:00
|
|
|
Discourse.redis.setex self.key(user_id), 1.day.to_i, token
|
2017-03-01 23:26:18 +08:00
|
|
|
token
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get(user_id)
|
2019-12-03 17:05:53 +08:00
|
|
|
Discourse.redis.get self.key(user_id)
|
2017-03-01 23:26:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.del(user_id)
|
2019-12-03 17:05:53 +08:00
|
|
|
Discourse.redis.del self.key(user_id)
|
2017-03-01 23:26:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.compare(user_id, token)
|
|
|
|
token == self.get(user_id)
|
|
|
|
end
|
|
|
|
end
|