1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Починка админки полностью22223

This commit is contained in:
MoonTestUse1
2025-01-01 23:36:40 +06:00
parent 09d97083d1
commit d777bc2131
2 changed files with 28 additions and 18 deletions

View File

@@ -1,26 +1,29 @@
"""Authentication routes"""
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Body
from sqlalchemy.orm import Session
from ..database import get_db
from ..crud import auth as auth_crud
from ..utils.loggers import auth_logger
from pydantic import BaseModel
router = APIRouter()
class LoginCredentials(BaseModel):
lastName: str
password: str
class AdminCredentials(BaseModel):
username: str
password: str
@router.post("/login")
async def login(credentials: dict, db: Session = Depends(get_db)):
async def login(credentials: LoginCredentials, db: Session = Depends(get_db)):
"""Employee login endpoint"""
try:
if not credentials.get("lastName") or not credentials.get("password"):
raise HTTPException(
status_code=400,
detail="Необходимо указать фамилию и пароль"
)
employee = auth_crud.authenticate_employee(
db,
credentials["lastName"],
credentials["password"]
credentials.lastName,
credentials.password
)
if not employee:
@@ -38,17 +41,11 @@ async def login(credentials: dict, db: Session = Depends(get_db)):
raise HTTPException(status_code=500, detail="Ошибка сервера")
@router.post("/admin")
async def admin_login(credentials: dict):
async def admin_login(credentials: AdminCredentials):
"""Admin login endpoint"""
try:
if not credentials.get("username") or not credentials.get("password"):
raise HTTPException(
status_code=400,
detail="Необходимо указать имя пользователя и пароль"
)
# Простая проверка для админа (в реальном приложении используйте безопасную аутентификацию)
if credentials["username"] == "admin" and credentials["password"] == "admin66":
if credentials.username == "admin" and credentials.password == "admin66":
return {"isAdmin": True}
raise HTTPException(