аутентификация к веб админке
This commit is contained in:
parent
595c9419f4
commit
e6967db17d
6 changed files with 282 additions and 2 deletions
60
LichessWebView/auth_config.py
Normal file
60
LichessWebView/auth_config.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
"""Модуль для загрузки конфигурации аутентификации"""
|
||||
import json
|
||||
import os
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
AUTH_CONFIG_PATH = "/app/auth_config.json"
|
||||
AUTH_CONFIG_EXAMPLE_PATH = "/app/auth_config.example.json"
|
||||
|
||||
|
||||
def load_auth_config() -> Optional[Dict]:
|
||||
"""
|
||||
Загружает конфигурацию аутентификации из файла.
|
||||
Возвращает None, если файл не найден.
|
||||
"""
|
||||
config_path = AUTH_CONFIG_PATH
|
||||
|
||||
# Если файл не существует, пробуем example
|
||||
if not os.path.exists(config_path):
|
||||
if os.path.exists(AUTH_CONFIG_EXAMPLE_PATH):
|
||||
print(f"Warning: {config_path} not found, using example config")
|
||||
config_path = AUTH_CONFIG_EXAMPLE_PATH
|
||||
else:
|
||||
print(f"Error: Neither {AUTH_CONFIG_PATH} nor {AUTH_CONFIG_EXAMPLE_PATH} found")
|
||||
return None
|
||||
|
||||
try:
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
config = json.load(f)
|
||||
return config
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Error parsing auth config: {e}")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Error loading auth config: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def get_users() -> List[Dict[str, str]]:
|
||||
"""
|
||||
Возвращает список пользователей из конфига.
|
||||
"""
|
||||
config = load_auth_config()
|
||||
if not config:
|
||||
return []
|
||||
|
||||
return config.get('users', [])
|
||||
|
||||
|
||||
def validate_credentials(username: str, password: str) -> bool:
|
||||
"""
|
||||
Проверяет правильность логина и пароля.
|
||||
"""
|
||||
users = get_users()
|
||||
|
||||
for user in users:
|
||||
if user.get('username') == username and user.get('password') == password:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue