Добавление нового типа пользователя + исправления из второй лабы

This commit is contained in:
Anton Kamalov
2024-11-04 21:01:39 +03:00
parent af6860446b
commit b0924ae0bc
10 changed files with 41 additions and 37 deletions

View File

@@ -12,11 +12,12 @@ def auth():
return render_template('auth.html')
else:
data = request.form.to_dict()
data['table'] = 'internal_users' if 'internal' in data else 'external_users'
auth_data = route(current_app.config['db_config'], data, sql_provider, 'auth.sql')
if auth_data.status:
session.update({
'login': auth_data.result[0]['login'],
'role': auth_data.result[0]['role'],
'role': auth_data.result[0]['user_role'],
'db_config': current_app.config['db_config'],
'permanent': True
})

View File

@@ -8,8 +8,10 @@ class InfoRespronse:
def route(db_config, input_data, sql_provider, name) -> InfoRespronse:
_sql = sql_provider.get(name, input_data)
print("sql = ", _sql)
# print("sql = ", _sql)
result = select_list(db_config, _sql)
if result is None or len(result) == 0:
return InfoRespronse(result, error_message = 'Произошла ошибка на этапе авторизации :(', status=False)
if result is None:
return InfoRespronse(result, error_message = 'Произошла ошибка на этапе авторизации', status=False)
elif len(result) == 0:
return InfoRespronse(result, error_message = 'Пользователь не найден', status=False)
return InfoRespronse(result, error_message='', status=True)

View File

@@ -1,4 +1,3 @@
SELECT login, role FROM user_table
WHERE 1=1
AND login = '$login'
SELECT login, user_role FROM $table
WHERE login = '$login'
AND password = '$password';

View File

@@ -13,6 +13,7 @@
<input type="text" name="login" required>
<label for="password">Пароль: </label>
<input type="password" name="password" required><br>
<p><input type="checkbox" name="internal">Внутренний пользователь</p>
<input type="submit" value="Вход">
</form>
</div>

View File

@@ -8,6 +8,6 @@
<body>
<h1>Сожалеем</h1>
<p>{{ error_message }}</p>
<p><a href="{{ url_for('auth_bp.auth') }}">Вернуться</a></p>
<a href="{{ url_for('index') }}"><button>На главную страницу</button></a>
</body>
</html>