Beispiel #1
0
def request_token():
    """
    request_token takes in email and password, returns the authentication token 

    Returns:
        [type]: [description]
    """
    if request.json is None:
        return Responses.OPERATION_FAILED()
    email = request.json.get('email', None)
    password = request.json.get('password', None)
    user = User.authenticate(email, password)
    # ensure email is confirmed
    if not user.email_confirmed:
        user.send_confirmation_email(user.email)
        return Responses.UNCONFIRMED_USER()

    if user:
        token = create_access_token(identity=user.token_identity())
        # refresh_token = create_refresh_token(identity=user.token_identity())
        response, status = res()
        set_access_cookies(response, token)
        # set_refresh_cookies(response, refresh_token)
        # identiti = get_jwt_identity()
        # print(identiti)
        # set token to httponly cookies
        return response, status
    return Responses.AUTHENTICATION_FAILED()
Beispiel #2
0
def update_user_information(email):
    """
    updates user by using email

    Args:
        email (string): 

    Returns:
        (string,int): user info if update succesful, otherwise response no need to update
    """
    user = User.get_user_by_email(email)
    if not user:
        return Responses.NOT_EXIST()
    if not user.email_confirmed:
        return Responses.UNCONFIRMED_USER()

    json_dict = request.json
    if len(user.update(json_dict)) > 0:  #['password']
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()