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

чиним билд115

This commit is contained in:
MoonTestUse1
2025-01-02 01:18:07 +06:00
parent 660cbfeedb
commit 05a92e0414
3 changed files with 15 additions and 53 deletions

View File

@@ -2,7 +2,7 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from . import models
from .routers import admin, employees, requests
from .routers import admin, employees, requests, auth
app = FastAPI()
@@ -16,6 +16,7 @@ app.add_middleware(
)
# Include routers
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
app.include_router(admin.router, prefix="/api/admin", tags=["admin"])
app.include_router(employees.router, prefix="/api/employees", tags=["employees"])
app.include_router(requests.router, prefix="/api/requests", tags=["requests"])

View File

@@ -1,60 +1,15 @@
"""Authentication routes"""
from fastapi import APIRouter, Depends, HTTPException, Body
"""Authentication router"""
from fastapi import APIRouter, Depends, HTTPException
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
from ..schemas.auth import AdminLogin
router = APIRouter()
class LoginCredentials(BaseModel):
lastName: str
password: str
class AdminCredentials(BaseModel):
username: str
password: str
@router.post("/login")
async def login(credentials: LoginCredentials, db: Session = Depends(get_db)):
"""Employee login endpoint"""
try:
employee = auth_crud.authenticate_employee(
db,
credentials.lastName,
credentials.password
)
if not employee:
raise HTTPException(
status_code=401,
detail="Неверные учетные данные"
)
return employee
except HTTPException:
raise
except Exception as e:
auth_logger.error(f"Login error: {e}", exc_info=True)
raise HTTPException(status_code=500, detail="Ошибка сервера")
@router.post("/admin")
async def admin_login(credentials: AdminCredentials):
def admin_login(login_data: AdminLogin, db: Session = Depends(get_db)):
"""Admin login endpoint"""
try:
# Простая проверка для админа (в реальном приложении используйте безопасную аутентификацию)
if credentials.username == "admin" and credentials.password == "admin66":
return {"isAdmin": True}
raise HTTPException(
status_code=401,
detail="Неверные учетные данные администратора"
)
except HTTPException:
raise
except Exception as e:
auth_logger.error(f"Admin login error: {e}", exc_info=True)
raise HTTPException(status_code=500, detail="Ошибка сервера")
if login_data.username == "admin" and login_data.password == "admin123":
return {"access_token": "admin_token"}
raise HTTPException(status_code=401, detail="Invalid credentials")

View File

@@ -0,0 +1,6 @@
"""Authentication schemas"""
from pydantic import BaseModel
class AdminLogin(BaseModel):
username: str
password: str