(user, max_tokens=5, expire=60 * 60 * 24)
return new_token
Creates and records a new reset token for
Creates and records a new reset token for
Creates and records a new reset token for
def add_token(user, max_tokens=5, expire=60 * 60 * 24):
    """
    Creates and records a new reset token for
    """
    r = current_app.redis

    new_token = _generate_token()
    token_key = _tokens_by_user(user)
    already_exists = r.exists(token_key)

    pipe = r.pipeline()
    pipe.lpush(token_key, new_token)
    pipe.ltrim(token_key, 0, max_tokens - 1)

    if not already_exists:
        # Only set/reset the expiry if the key didn't already
        # exist.
        pipe.expire(token_key, expire)

    pipe.execute()

    return new_token
def add_token ( user , max_tokens = 5 , expire = 60 * 60 * 24 ) : r = current_app . redis new_token = _generate_token ( ) token_key = _tokens_by_user ( user ) already_exists = r . exists ( token_key ) pipe = r . pipeline ( ) pipe . lpush ( token_key , new_token ) pipe . ltrim ( token_key , 0 , max_tokens - 1 ) if not already_exists : # Only set/reset the expiry if the key didn't already # exist. pipe . expire ( token_key , expire ) pipe . execute ( ) return new_token