Esempio n. 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()
Esempio n. 2
0
def quiz_form():
    json_dict = request.json
    quiz = QuizForm()
    error = quiz.update(json_dict)
    print(request.json)
    # print(error)
    if len(error) > 0:
        return Responses.OPERATION_FAILED()
    return res(quiz.as_dict())
Esempio n. 3
0
def password_update():
    json_dict = request.json
    user = User.get_user_by_email(json_dict['email'])

    error = user.update(json_dict['password'])

    if len(error) > 0:
        return Responses.OPERATION_FAILED()
    else:
        return Responses.SUCCESS()
Esempio n. 4
0
def register_user():
    """
    registers a new user

    """
    json_dict = request.json
    print(json_dict)
    user = User()
    user.update_from_dict(json_dict, ['id', 'role_id', 'role'])
    existing_user = User.get_user_by_email(json_dict['email'])
    if existing_user:
        return Responses.OBJECT_EXIST()
    error = user.update()
    if len(error) > 0:
        return Responses.OPERATION_FAILED()
    user.send_confirmation_email(json_dict['email'])
    flash(
        'Thanks for registering!  Please check your email to confirm your email address.',
        'success')
    return res(user.as_dict())
Esempio n. 5
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()