mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Починка админки полностью22223
This commit is contained in:
@@ -1,26 +1,29 @@
|
|||||||
"""Authentication routes"""
|
"""Authentication routes"""
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException, Body
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from ..database import get_db
|
from ..database import get_db
|
||||||
from ..crud import auth as auth_crud
|
from ..crud import auth as auth_crud
|
||||||
from ..utils.loggers import auth_logger
|
from ..utils.loggers import auth_logger
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
class LoginCredentials(BaseModel):
|
||||||
|
lastName: str
|
||||||
|
password: str
|
||||||
|
|
||||||
|
class AdminCredentials(BaseModel):
|
||||||
|
username: str
|
||||||
|
password: str
|
||||||
|
|
||||||
@router.post("/login")
|
@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"""
|
"""Employee login endpoint"""
|
||||||
try:
|
try:
|
||||||
if not credentials.get("lastName") or not credentials.get("password"):
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=400,
|
|
||||||
detail="Необходимо указать фамилию и пароль"
|
|
||||||
)
|
|
||||||
|
|
||||||
employee = auth_crud.authenticate_employee(
|
employee = auth_crud.authenticate_employee(
|
||||||
db,
|
db,
|
||||||
credentials["lastName"],
|
credentials.lastName,
|
||||||
credentials["password"]
|
credentials.password
|
||||||
)
|
)
|
||||||
|
|
||||||
if not employee:
|
if not employee:
|
||||||
@@ -38,17 +41,11 @@ async def login(credentials: dict, db: Session = Depends(get_db)):
|
|||||||
raise HTTPException(status_code=500, detail="Ошибка сервера")
|
raise HTTPException(status_code=500, detail="Ошибка сервера")
|
||||||
|
|
||||||
@router.post("/admin")
|
@router.post("/admin")
|
||||||
async def admin_login(credentials: dict):
|
async def admin_login(credentials: AdminCredentials):
|
||||||
"""Admin login endpoint"""
|
"""Admin login endpoint"""
|
||||||
try:
|
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}
|
return {"isAdmin": True}
|
||||||
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|||||||
@@ -13,6 +13,19 @@ server {
|
|||||||
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
|
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
|
||||||
gzip_disable "MSIE [1-6]\.";
|
gzip_disable "MSIE [1-6]\.";
|
||||||
|
|
||||||
|
# API proxy
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://support-backend:8000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_cache_bypass $http_upgrade;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||||
|
|||||||
Reference in New Issue
Block a user