distribusi-verse: medium-tech web app content management system for the web
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

24 lines
913 B

import os
from flask_login import current_user
from usermodel import User
from forms.loginform import LoginForm
def LoginUser():
loginform = LoginForm()
if loginform.validate_on_submit():
try:
user = User.query.filter_by(email=loginform.email.data).first()
if user is None:
loginform.password.errors.append("Invalid email or password!")
return render_template("login.html", loginform=loginform)
if check_password_hash(user.password, loginform.password.data):
login_user(user)
flash("Logged in successfully.", "success")
else:
flash("Invalid email or password!", "danger")
loginform.password.errors.append("Invalid email or password!")
return loginform
except Exception as e:
flash(e, "danger")
return loginform