from flask import Blueprint,render_template,request,redirect,url_for,session from werkzeug.security import check_password_hash from database.models import WebUser auth = Blueprint('auth',__name__) @auth.route("/") @auth.route("/login",methods=["GET"]) def login_template(): return render_template("login.html") @auth.route("/login",methods=["POST"]) def login(): username = request.form.get("username") password = request.form.get("password") if (not username) or (not password): return "Enter username/password" # TODO: Write simple frontened (if username is None or password is None) if (WebUser.userExists(username)): user = WebUser.get(WebUser.username == username) if ( check_password_hash(user.password_hash,password)): session["username"] = username return redirect(url_for("admin.admin_page")) else: return "Password not valid" return "User not exist" @auth.route("/logout") def logout(): # Logout from account return redirect(url_for("auth.login"))