Авторизация
+ интеграция с другими запросами
This commit is contained in:
28
App/Auth/auth_route.py
Normal file
28
App/Auth/auth_route.py
Normal 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 'Неправильный логин или пароль'
|
||||
Reference in New Issue
Block a user