Ejemplo n.º 1
0
def process_token(token_form):

    token_form = json.loads(request.form['token'])
    token_form = sanitize.form_keys(token_form)

    provided_token = Token.map_from_form(token_form)
    stored_token = user_select.token(provided_token)
    
    validate.token(stored_token, provided_token)
    
    provided_token.update()
    user_update.token(provided_token)

    return provided_token
Ejemplo n.º 2
0
def login():

    '''Called when a user is loging in (shocker)
    Checks the provided email and password with the values stored in the database'''

    credentials_form = json.loads(request.form['payload'])
    credentials_form = sanitize.form_keys(credentials_form)

    provided_credentials = Credentials.map_from_form(credentials_form)
    stored_credentials = user_select.login_credentials(provided_credentials)

    try:
        validate.login(stored_credentials, provided_credentials)
    
    except InvalidCredential as invalid:
        return response.error(invalid.args[0])

    token = Token()
    token.user_id = stored_credentials.id
    token.update()

    user_update.token(token)
    
    return response.add_token(token = token)