This is a reusable plain version the varia library website. You can host your own website of books using just a simple csv file
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.

31 lines
1.3 KiB

11 months ago
from flask import abort, flash, redirect, render_template, request, url_for
from flask_bcrypt import check_password_hash
11 months ago
from flask_login import login_user
from application.forms.loginform import LoginForm
7 months ago
from application.models.usermodel import User
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")
next = request.args.get("next")
if next is not None and not is_safe_url(next): # noqa: F821
return abort(400)
return redirect(next or url_for("index"))
else:
flash("Invalid email or password!", "danger")
loginform.password.errors.append("Invalid email or password!")
return render_template("user/login.html", loginform=loginform)
except Exception as e:
flash(e, "danger")
7 months ago
return render_template("user/login.html", loginform=loginform)