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 = Blueprint('admin',__name__)
|
||||||
|
|
||||||
@admin.route("/admin")
|
@admin.route("/")
|
||||||
def admin_page():
|
def admin_page():
|
||||||
if ( "username" in session):
|
if ( "username" in session):
|
||||||
return render_template("admin.html",username=session["username"])
|
return render_template("index.html",username=session["username"])
|
||||||
|
return redirect(url_for("auth.login_page"))
|
||||||
return redirect(url_for("login/"))
|
|
||||||
|
|
26
apps/auth.py
26
apps/auth.py
|
@ -1,33 +1,27 @@
|
||||||
from flask import Blueprint,render_template,request,redirect,url_for,session
|
from flask import Blueprint,render_template,request,redirect,url_for,session
|
||||||
from werkzeug.security import check_password_hash
|
from werkzeug.security import check_password_hash
|
||||||
|
from flask import flash
|
||||||
from database import WebUser
|
from database import WebUser
|
||||||
|
|
||||||
auth = Blueprint('auth',__name__)
|
auth = Blueprint('auth',__name__)
|
||||||
|
|
||||||
@auth.route("/")
|
|
||||||
@auth.route("/login",methods=["GET"])
|
@auth.route("/login",methods=["GET"])
|
||||||
def login_template():
|
def login_template():
|
||||||
return render_template("login.html")
|
return render_template("login.html")
|
||||||
|
|
||||||
@auth.route("/login",methods=["POST"])
|
@auth.route("/login",methods=["POST"])
|
||||||
def login():
|
def login_page():
|
||||||
username = request.form.get("username")
|
username = request.form["username"]
|
||||||
password = request.form.get("password")
|
password = request.form["password"]
|
||||||
|
|
||||||
if (not username) or (not password):
|
user = WebUser.get_or_none(WebUser.username == username)
|
||||||
return "Enter username/password"
|
|
||||||
|
|
||||||
# TODO: Write simple frontened (if username is None or password is None)
|
if (user) and (check_password_hash(user.password_hash,password)):
|
||||||
if (WebUser.userExists(username)):
|
session["username"] = username
|
||||||
user = WebUser.get(WebUser.username == username)
|
return redirect(url_for("admin.admin_page"))
|
||||||
|
|
||||||
if ( check_password_hash(user.password_hash,password)):
|
flash("password/username not valid")
|
||||||
session["username"] = username
|
return redirect(url_for("auth.login_page"))
|
||||||
return redirect(url_for("admin.admin_page"))
|
|
||||||
else:
|
|
||||||
return "Password not valid"
|
|
||||||
return "User not exist"
|
|
||||||
|
|
||||||
@auth.route("/logout")
|
@auth.route("/logout")
|
||||||
def 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