29 lines
959 B
Python
29 lines
959 B
Python
from flask import (Blueprint, redirect, render_template, request, session,
|
|
url_for)
|
|
|
|
from .auth_model import auth_model
|
|
|
|
auth_bp = Blueprint("auth_bp", __name__, template_folder="templates")
|
|
|
|
|
|
@auth_bp.route("/", methods=["GET", "POST"])
|
|
def auth():
|
|
if request.method == "GET":
|
|
return render_template("auth.html")
|
|
else:
|
|
data = request.form.to_dict()
|
|
auth_data = auth_model(data)
|
|
if auth_data.status:
|
|
session.update(
|
|
{
|
|
"user_id": auth_data.result[0]["user_ID"],
|
|
"login": auth_data.result[0]["login"],
|
|
"access_user": data["access"],
|
|
"role": auth_data.result[0]["user_role"],
|
|
"permanent": True,
|
|
}
|
|
)
|
|
return redirect(url_for("index"))
|
|
else:
|
|
return render_template("error.html", error_message=auth_data.error_message)
|