Fix log in
This commit is contained in:
parent
dcaafa6b95
commit
7ebd66d53c
|
@ -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"))
|
||||
|
|
24
apps/auth.py
24
apps/auth.py
|
@ -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 ( check_password_hash(user.password_hash,password)):
|
||||
if (user) and (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():
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Web group moderator</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
Admin panel
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue