示例#1
0
def verify_token(user_id, topic, token):
    if not token:
        return False
    conn = cache.get_connection()
    k = "verifications:token:%s:%s" % (str(user_id), str(topic))
    r = (conn.get(k) or b"").decode("utf-8").upper()
    return (r and token and (r == token))
示例#2
0
def verify_pin(user_id, topic, pin):
    if not pin:
        return False
    conn = cache.get_connection()
    k = "verifications:pin:%s:%s" % (str(user_id), str(topic))
    r = int(conn.get(k) or 0)
    return (r and pin and (r == pin))
示例#3
0
def create_pin(user_id, topic, expire=300):
    if not (user_id and topic):
        raise Exception("Need user id and subject for pin verification")
    conn = cache.get_connection()
    k = "verifications:pin:%s:%s" % (str(user_id), str(topic))
    pin = random.randint(100000, 999999)
    conn.setex(k, expire, pin)
    return pin
示例#4
0
def create_token(user_id, topic, expire=300):
    if not (user_id and topic):
        raise Exception("Need user id and subject for pin verification")
    conn = cache.get_connection()
    k = "verifications:token:%s:%s" % (str(user_id), str(topic))
    token = str(uuid.uuid4()).upper()
    conn.setex(k, expire, token)
    return token
示例#5
0
 def __init__(self):
     self.cache = cache.get_connection()
     self.prefix = "post-edits"