Fix log in

This commit is contained in:
hok7z 2022-12-02 23:12:00 +02:00
parent dcaafa6b95
commit 7ebd66d53c
4 changed files with 15 additions and 35 deletions

View File

@ -3,9 +3,8 @@ from werkzeug.security import generate_password_hash
admin = Blueprint('admin',__name__)
@admin.route("/admin")
@admin.route("/")
def admin_page():
if ( "username" in session):
return render_template("admin.html",username=session["username"])
return redirect(url_for("login/"))
return render_template("index.html",username=session["username"])
return redirect(url_for("auth.login_page"))

View File

@ -1,33 +1,27 @@
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("/")
@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")
def login_page():
username = request.form["username"]
password = request.form["password"]
if (not username) or (not password):
return "Enter username/password"
user = WebUser.get_or_none(WebUser.username == username)
# TODO: Write simple frontened (if username is None or password is None)
if (WebUser.userExists(username)):
user = WebUser.get(WebUser.username == username)
if (user) and (check_password_hash(user.password_hash,password)):
session["username"] = username
return redirect(url_for("admin.admin_page"))
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"
flash("password/username not valid")
return redirect(url_for("auth.login_page"))
@auth.route("/logout")
def logout():

View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Web group moderator</title>
</head>
<body>
Admin panel
</body>
</html>