Авторизация

+ интеграция с другими запросами
This commit is contained in:
Anton Kamalov
2024-10-22 01:29:32 +03:00
parent 339a55f8da
commit d1f513e106
7 changed files with 75 additions and 7 deletions

28
App/Auth/auth_route.py Normal file
View File

@@ -0,0 +1,28 @@
from flask import request, Blueprint, render_template, session, redirect, url_for
from os import path
from db.sql_provider import SQLProvider
from db.select import select_list
import json
sql_provider = SQLProvider(path.join(path.dirname(__file__), 'sql'))
auth_bp = Blueprint('auth_bp', __name__, template_folder='templates')
with open(path.join(path.dirname(__file__), 'config.json')) as f:
config = json.load(f)
@auth_bp.route('/', methods=['GET', 'POST'])
def auth():
if request.method == 'GET':
return render_template('auth.html')
else:
data = dict(request.form)
print(data)
result = select_list(config, sql_provider.get('auth.sql', data))
if result[1]:
session['user_id'] = result[1][0]['user_ID']
session['role'] = result[1][0]['role']
session['db_config'] = config
session.permanent = True
return redirect(url_for('index'))
else:
return 'Неправильный логин или пароль'