from flask import Blueprint,render_template,request,redirect,url_for,session from werkzeug.security import check_password_hash from flask import flash from database import WebUser auth = Blueprint('auth',__name__) @auth.route("/login",methods=["GET"]) def login_template(): return render_template("login.html") @auth.route("/login",methods=["POST"]) def login_page(): username = request.form["username"] password = request.form["password"] user = WebUser.get_or_none(WebUser.username == username) if (user) and (check_password_hash(user.password_hash,password)): session["username"] = username return redirect(url_for("admin.admin_page")) flash("wrong nickname/password!") return redirect(url_for("auth.login_page")) @auth.route("/logout") def logout(): # Logout from account return redirect(url_for("auth.login"))