Ejemplo n.º 1
0
def get_uid(token):
    key = TOKEN_TOKEN % token
    value = redistore.get(key)
    if not value:
        return -1
    value = int(value)
    pipe = redistore.pipeline()
    pipe.delete(key)
    pipe.delete(TOKEN_UID % value)
    logger.info(pipe.execute())
    return value
Ejemplo n.º 2
0
def validate_token(uid, token):
    key = TOKEN_TOKEN % token
    value = redistore.get(key)
    if not value:
        return False
    if int(value) != uid:
        return False
    pipe = redistore.pipeline()
    pipe.delete(key)
    pipe.delete(TOKEN_UID % uid)
    logger.info(pipe.execute())
    return True
Ejemplo n.º 3
0
def make_token(uid, expire=TOKEN_EXPIRE):
    #check if user got a token
    uid_key = TOKEN_UID % uid
    key = redistore.get(uid_key)
    if key:
        return key

    token = create_token(TOKEN_LENGTH)
    while redistore.get(key):
        token = create_token(TOKEN_LENGTH)
    key = TOKEN_TOKEN % token
    pipe = redistore.pipeline()
    pipe.setex(key, uid, expire)
    pipe.setex(uid_key, token, expire)
    logger.info(pipe.execute())
    return token