pre-commit changes
This commit is contained in:
@@ -1,23 +1,28 @@
|
||||
from flask import Blueprint, render_template, redirect, url_for, request, session
|
||||
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 = Blueprint("auth_bp", __name__, template_folder="templates")
|
||||
|
||||
@auth_bp.route('/', methods=['GET', 'POST'])
|
||||
|
||||
@auth_bp.route("/", methods=["GET", "POST"])
|
||||
def auth():
|
||||
if request.method == 'GET':
|
||||
return render_template('auth.html')
|
||||
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'))
|
||||
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)
|
||||
return render_template("error.html", error_message=auth_data.error_message)
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
|
||||
from Database.work import select_list
|
||||
from Database.sql_provider import SQLProvider
|
||||
|
||||
from Database.work import select_list
|
||||
from flask import current_app
|
||||
import os
|
||||
|
||||
sql_provider = SQLProvider(os.path.join(os.path.dirname(__file__), 'sql'))
|
||||
sql_provider = SQLProvider(os.path.join(os.path.dirname(__file__), "sql"))
|
||||
|
||||
|
||||
@dataclass
|
||||
class InfoRespronse:
|
||||
result: tuple
|
||||
error_message: str
|
||||
status: bool
|
||||
|
||||
def auth_model(input_data) -> InfoRespronse:
|
||||
db_config = current_app.config['db_config']
|
||||
|
||||
_sql = sql_provider.get('auth.sql', input_data)
|
||||
def auth_model(input_data) -> InfoRespronse:
|
||||
db_config = current_app.config["db_config"]
|
||||
|
||||
_sql = sql_provider.get("auth.sql", input_data)
|
||||
user = select_list(db_config, _sql)
|
||||
if user is None:
|
||||
return InfoRespronse((),
|
||||
error_message = 'Ошибка при подключении к БД',
|
||||
status=False)
|
||||
return InfoRespronse(
|
||||
(), error_message="Ошибка при подключении к БД", status=False
|
||||
)
|
||||
elif len(user) == 0:
|
||||
return InfoRespronse((),
|
||||
error_message = 'Пользователь не найден',
|
||||
status=False)
|
||||
return InfoRespronse(user, error_message='', status=True)
|
||||
return InfoRespronse((), error_message="Пользователь не найден", status=False)
|
||||
return InfoRespronse(user, error_message="", status=True)
|
||||
|
||||
Reference in New Issue
Block a user