I have an api using flask and flask-pymongo Im trying to deal with a login function and using passlib try and check if a password hash matches
Im getting a 500 server error when making a call to the endpoint
My code is as follows:
def login():
email = request.form['email']
password = request.form['password']
# Find user record by email
user = db.user.find_one({'email': email})
# If user not found return message
if not user:
return jsonify(message='We cannot find you, please sign up')
# If user found check password and return token
hashed = user.password
test = pbkdf2_sha256.verify(password, hashed)
# Returns on success
if test:
access_token = create_access_token(identity=email)
return jsonify(message='Login Successful', access_token=access_token), 202
else:
return jsonify(message='Password incorrect'), 403
the error is here
TypeError: The view function for 'login' did not return a valid response. The function either returned None or ended without a return statement.
127.0.0.1 - - [29/Aug/2021 20:24:37] "POST /login HTTP/1.1" 500 -
as I Am new to Python I'm wondering if Im using the return correctly here
hashed = user.password