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

Fix database

This commit is contained in:
MoonTestUse1
2025-01-07 05:26:33 +06:00
parent d9e276ad6b
commit bdf4ae9d70
29 changed files with 727 additions and 531 deletions

View File

@@ -6,7 +6,7 @@ from typing import Optional
from ..database import get_db
from ..crud import employees
from ..schemas.auth import Token
from ..schemas.auth import Token, LoginCredentials
from ..utils.auth import verify_password
from ..utils.jwt import create_and_save_token
@@ -19,8 +19,18 @@ async def login_for_access_token(
db: Session = Depends(get_db)
):
"""Авторизация сотрудника"""
# Разделяем username на имя и фамилию
try:
first_name, last_name = form_data.username.split()
except ValueError:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Username should be in format: 'First Last'",
headers={"WWW-Authenticate": "Bearer"},
)
# Проверяем учетные данные сотрудника
employee = employees.get_employee_by_last_name(db, form_data.username)
employee = employees.get_employee_by_credentials(db, first_name, last_name)
if not employee or not verify_password(form_data.password, employee.hashed_password):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
@@ -42,8 +52,18 @@ async def admin_login(
db: Session = Depends(get_db)
):
"""Авторизация администратора"""
# Разделяем username на имя и фамилию
try:
first_name, last_name = form_data.username.split()
except ValueError:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Username should be in format: 'First Last'",
headers={"WWW-Authenticate": "Bearer"},
)
# Проверяем учетные данные администратора
employee = employees.get_employee_by_last_name(db, form_data.username)
employee = employees.get_employee_by_credentials(db, first_name, last_name)
if not employee or not employee.is_admin or not verify_password(form_data.password, employee.hashed_password):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,