Beispiel #1
0
def token_verify(token):
    secret_key = current_app.config.get('SECRET_KEY')
    try:
        data = jwt.decode(token, secret_key, algorithm='HS256')
        return UserService.instance().get_one_or_fail(data['id'])
    except jwt.DecodeError:
        return False
Beispiel #2
0
def auth_login(email: fields.Email(), password: fields.String()):
    user = UserService.instance().login(email, password)

    if not user:
        raise HTTPBadRequest("login", "failed")

    token_data = dict(id=user.id)
    return {"token": token_generate(token_data)}