def post(self): # post a user using valid credentials try: data = api.payload email = data['email'] password = data['password'] # checks if the email exists if UserModel.check_email_exist(email): # checks if the password is valid if UserModel.check_password(email, password): return {'status': 'User successfully logged in'}, 200 else: return {'status': 'Wrong login credentials!'}, 401 else: return {'status': 'Email does not exist!'}, 401 except KeyError as e: api.abort(500, e.__doc__, status="Could not perform this action", statusCode="500") except KeyError as e: api.abort(400, e.__doc__, status="Could not perform this action", statusCode="400")
def post(self): data = api.payload email = data['email'] password = data['password'] if UserModel.check_email_exist(email): if UserModel.check_password(email,password): return {"message":"Successfully logged in"} else: return {"message":"Wrong login credentials!"} else: return {"message":"Email does not exist!"}
def login(): if request.method == 'POST': email = request.form['email'] password = request.form['password'] # Check if email exists if UserModel.check_email_exist(email): # Check if the password is valid if UserModel.check_password(email, password): session['logged_in'] = True session['username'] = UserModel.fetch_by_email(email).username session['id'] = UserModel.fetch_by_email(email).id return redirect(url_for('home')) else: flash('Wrong login credentials! Please Try Again!!', 'danger') return redirect(url_for('login')) else: flash('Email does not exist', 'danger') return render_template('login.html')