mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 17:15:32 +08:00
0d3d2c43a0
This commit also adds a rubocop rule to prevent global variables.
31 lines
522 B
Ruby
31 lines
522 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
|
|
Discourse.redis.setex self.key(user_id), 1.day.to_i, token
|
|
token
|
|
end
|
|
|
|
def self.get(user_id)
|
|
Discourse.redis.get self.key(user_id)
|
|
end
|
|
|
|
def self.del(user_id)
|
|
Discourse.redis.del self.key(user_id)
|
|
end
|
|
|
|
def self.compare(user_id, token)
|
|
token == self.get(user_id)
|
|
end
|
|
end
|