Pack of changes (auth and requests)

This commit is contained in:
Anton Kamalov
2024-10-22 21:48:18 +03:00
parent d1f513e106
commit c5bd8c03e4
10 changed files with 101 additions and 64 deletions

30
App/Auth/auth.py Normal file
View File

@@ -0,0 +1,30 @@
from flask import request, Blueprint, render_template, session, redirect, url_for
from os import path
from .auth_route import route
from Database.sql_provider import SQLProvider
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 = request.form.to_dict()
print(data)
auth_data = route(config, data, sql_provider, 'auth.sql')
if auth_data.status:
session.update({
'user_id': auth_data.result[0]['user_ID'],
'role': auth_data.result[0]['role'],
'db_config': config,
'permanent': True
})
return redirect(url_for('index'))
else:
return auth_data.error_message