Ejemplo n.º 1
0
def login():
    print('Enter login route')
    # To log user in and return an authentication token
    # Body: {email, password}
    # Return {auth_token}    
    body = request.json
    first_nam = request.json.get('username', None)

    to_check = User.query.filter_by(email=body['email']).first()
    if to_check == None:
        return 'No user record found in db'

    if bcrypt.check_password_hash(to_check.password, body['password']):
         # Create JWT token and return it
        print(f'bcrypt.check_password_hash(  passed!')     
        access_token = create_access_token(to_check.id)
        print(f'create_access_token(to_check.id) passed!')
        return{
            'message': 'Hey you logged in fine',
            'access_token'  :  access_token                   #This appears in Postman
        }
    else:
        return {
            'message': 'Incorrect password'
        }  
Ejemplo n.º 2
0
def client_login(data):
    message = "Login failure."
    my_client = Client.is_client(data["email"])
    token = None
    if my_client:
        if bcrypt.check_password_hash(my_client.password, data["password"]):
            token = create_access_token(identity=my_client.id)
            message = "Successfully logged in."
    return token, message
Ejemplo n.º 3
0
def login():
    body = request.json

    check_if_user_exists = Users.query.filter_by(email=body['email']).first()
    check_if_pw_matches = bcrypt.check_password_hash(
        check_if_user_exists.password, body['password'])

    if check_if_pw_matches:
        access_token = create_access_token(check_if_user_exists.id)
        return jsonify({
            'message': 'You have logged in.',
            'Your login token is': access_token
        }), 200
    else:
        return 'Incorrect password, please try again.'
Ejemplo n.º 4
0
def login():
    body = request.json
    # email = body['email']
    # password = body['password']

    check_client = Client.query.filter_by(email=body['email']).first()
    if bcrypt.check_password_hash(check_client.password,
                                  password=body['password']):

        access_token = create_access_token(check_client.id)

        return {'message': 'logged in', 'token': access_token}

    else:
        return {'message': 'try again'}
Ejemplo n.º 5
0
def login():
    # To log a user in and return an authentication token
    # Body: { username, password }
    # Return: { auth_token }
    body = request.json
    to_check = User.query.filter_by(email=body["email"]).first()

    if bcrypt.check_password_hash(to_check.password, body["password"]):
        # Create JWT token and return it
        access_token = create_access_token(identity=to_check.id)
        message = {"message": "Hey, you logged in.", "token": access_token}
    else:
        message = {"message": "Incorrect password."}

    return message