Files
roa2web-service-auto/reports-app/backend/app/routers/auth.py
Marius Mutu f42eff71a6 Fix .gitignore and add missing authentication source files
This commit fixes overly broad .gitignore patterns that were excluding
important source code files from version control. Previously, wildcard
patterns like *auth*, *token*, *secret*, *connection*, and *credential*
were excluding ALL files containing these words, including critical
application code.

Changes:
- Updated .gitignore with specific patterns for sensitive config files
  (*.json, *.txt, *.yml, *.yaml extensions only)
- Removed broad wildcards that excluded source code files

Added missing source files:
- shared/auth/ (9 files): Complete authentication system
  - JWT handler, middleware, auth service, models, routes
- reports-app/backend/app/routers/auth.py: Authentication API router
- reports-app/backend/app/auth_middleware_wrapper.py: Middleware wrapper
- reports-app/frontend/src/stores/auth.js: Vue.js auth store
- reports-app/frontend/tests/: E2E tests and fixtures for auth
- reports-app/telegram-bot/app/auth/: Telegram auth linking module
- deployment/windows/scripts/Setup-ClaudeAuth.ps1: Windows deployment script
- security/secrets_scanner.py: Security scanning utility

These files are essential for the application to function and should
have been included in the initial commit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-25 15:02:28 +03:00

109 lines
3.4 KiB
Python

"""
API Router pentru autentificare - Wrapper peste shared auth
"""
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.security import HTTPBearer
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '../../../../shared'))
from auth.dependencies import get_current_user
from auth.models import LoginRequest, TokenResponse, CurrentUser
from auth.auth_service import auth_service
from pydantic import BaseModel
router = APIRouter()
security = HTTPBearer()
class LogoutResponse(BaseModel):
"""Răspuns pentru logout"""
message: str
success: bool
@router.post("/login", response_model=TokenResponse)
async def login(login_request: LoginRequest):
"""
Autentificare utilizator cu username și parola
Folosește shared auth service pentru validarea credențialelor
și generarea token-urilor JWT
"""
try:
# Folosește shared auth service pentru autentificare
success, token_response, error_message = await auth_service.authenticate_and_create_tokens(
username=login_request.username,
password=login_request.password
)
if not success:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=error_message or "Authentication failed",
headers={"WWW-Authenticate": "Bearer"},
)
return token_response
except HTTPException:
raise # Re-raise HTTP exceptions as-is
except Exception as e:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Internal authentication error"
)
@router.post("/logout", response_model=LogoutResponse)
async def logout(current_user: CurrentUser = Depends(get_current_user)):
"""
Logout utilizator
Pentru moment doar confirmă logout-ul (token-urile JWT nu sunt invalidate server-side)
În viitor poate fi extins cu blacklist de token-uri
"""
try:
return LogoutResponse(
message=f"Utilizatorul {current_user.username} a fost deconectat cu succes",
success=True
)
except Exception as e:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Eroare la logout: {str(e)}"
)
@router.get("/me", response_model=CurrentUser)
async def get_current_user_info(current_user: CurrentUser = Depends(get_current_user)):
"""
Obține informațiile utilizatorului curent
Returnează datele utilizatorului din token-ul JWT
"""
return current_user
@router.post("/refresh")
async def refresh_token(refresh_token: str):
"""
Reîmprospătează token-ul de acces folosind refresh token-ul
Această funcție va fi implementată în viitor pentru gestionarea
completă a ciclului de viață al token-urilor
"""
raise HTTPException(
status_code=status.HTTP_501_NOT_IMPLEMENTED,
detail="Refresh token nu este încă implementat"
)
@router.get("/validate")
async def validate_token(current_user: CurrentUser = Depends(get_current_user)):
"""
Validează token-ul curent
Endpoint util pentru frontend să verifice dacă token-ul este încă valid
"""
return {
"valid": True,
"user": current_user.username,
"companies": current_user.companies,
"message": "Token valid"
}