2022-09-01 09:24:40 -04:00
|
|
|
from flask import Blueprint,render_template,request,redirect,url_for,session
|
2022-08-29 12:10:44 -04:00
|
|
|
from werkzeug.security import check_password_hash
|
2022-12-02 16:12:00 -05:00
|
|
|
from flask import flash
|
2022-11-26 12:22:25 -05:00
|
|
|
from database import WebUser
|
2022-09-01 09:24:40 -04:00
|
|
|
|
2022-08-29 12:10:44 -04:00
|
|
|
auth = Blueprint('auth',__name__)
|
|
|
|
|
|
|
|
@auth.route("/login",methods=["GET"])
|
|
|
|
def login_template():
|
|
|
|
return render_template("login.html")
|
|
|
|
|
|
|
|
@auth.route("/login",methods=["POST"])
|
2022-12-02 16:12:00 -05:00
|
|
|
def login_page():
|
|
|
|
username = request.form["username"]
|
|
|
|
password = request.form["password"]
|
2022-08-29 12:10:44 -04:00
|
|
|
|
2022-12-02 16:12:00 -05:00
|
|
|
user = WebUser.get_or_none(WebUser.username == username)
|
2022-09-01 09:24:40 -04:00
|
|
|
|
2022-12-02 16:12:00 -05:00
|
|
|
if (user) and (check_password_hash(user.password_hash,password)):
|
|
|
|
session["username"] = username
|
|
|
|
return redirect(url_for("admin.admin_page"))
|
|
|
|
|
2022-12-11 08:51:44 -05:00
|
|
|
flash("wrong nickname/password!")
|
2022-12-02 16:12:00 -05:00
|
|
|
return redirect(url_for("auth.login_page"))
|
2022-08-29 12:10:44 -04:00
|
|
|
|
|
|
|
@auth.route("/logout")
|
|
|
|
def logout():
|
|
|
|
# Logout from account
|
|
|
|
return redirect(url_for("auth.login"))
|