class Redis::EmailSignupVerification

Constants

EXPIRE
VERSION

Public Class Methods

new(opts = {}) click to toggle source
# File lib/redis/email_signup_verification/redis_ext.rb, line 5
def initialize(opts = {})
  @redis = opts.delete(:redis) || Redis.new(opts)
end

Public Instance Methods

created_at(token) click to toggle source
# File lib/redis/email_signup_verification/redis_ext.rb, line 27
def created_at(token)
  Time.parse @redis.hget(token, "created_at")
end
email(token) click to toggle source
# File lib/redis/email_signup_verification/redis_ext.rb, line 19
def email(token)
  @redis.hget(token, "email")
end
generate(email, password, expire: EXPIRE) click to toggle source
# File lib/redis/email_signup_verification/redis_ext.rb, line 9
def generate(email, password, expire: EXPIRE)
  token = generate_token
  set_key(email, password, token, expire)
  token
end
get(token) click to toggle source
# File lib/redis/email_signup_verification/redis_ext.rb, line 15
def get(token)
  get_key token
end
password(token) click to toggle source
# File lib/redis/email_signup_verification/redis_ext.rb, line 23
def password(token)
  @redis.hget(token, "password")
end

Private Instance Methods

generate_token() click to toggle source
# File lib/redis/email_signup_verification/redis_ext.rb, line 49
def generate_token
  SecureRandom.urlsafe_base64 40
end
get_key(token) click to toggle source
# File lib/redis/email_signup_verification/redis_ext.rb, line 40
def get_key(token)
  {
    token: token,
    email: email(token),
    password: password(token),
    created_at: created_at(token)
  } 
end
set_key(email, password, token, expire) click to toggle source
# File lib/redis/email_signup_verification/redis_ext.rb, line 33
def set_key(email, password, token, expire)
  @redis.hset(token, "email", email)
  @redis.hset(token, "password", BCrypt::Password.create(password))
  @redis.hset(token, "created_at", Time.now)
  @redis.expire(token, expire)
end