This commit adds a complete email authentication flow for the Telegram bot, allowing users to login with email + password instead of web app linking codes. Includes critical bug fixes for Oracle integration. **New Features:** - Email-based 2FA authentication with 6-digit codes sent via SMTP - Backend endpoints: verify-email and login-with-email - ConversationHandler for email authentication flow in Telegram bot - Session token verification to prevent user ID spoofing - Rate limiting (5 attempts per 5 minutes) - Email code expiry (5 minutes) with automatic cleanup **Bug Fixes:** - Fixed Oracle column name: ACTIV → INACTIV (with inverted logic) - Fixed Oracle password verification: verificautilizator returns checksum, not user_id - Fixed username case sensitivity: Oracle usernames must be uppercase - Fixed SMTP connection: use start_tls parameter instead of manual STARTTLS - Added middleware exclusions for public email auth endpoints **Backend Changes:** - Added verify-email endpoint (public) in telegram.py - Added login-with-email endpoint (public) with rate limiting and session verification - Updated middleware exclusions in main.py and auth_middleware_wrapper.py - Added AUTH_SESSION_SECRET configuration for session token signing **Telegram Bot Changes:** - New modules: app/auth/email_auth.py, app/bot/email_handlers.py - New utilities: app/utils/email_service.py (SMTP email sending) - Updated handlers.py: ignore callbacks handled by ConversationHandler - Updated menus.py: show Login button for unauthenticated users - Updated API client: verify_email() and login_with_email() methods - Database: email_auth_codes table with cleanup task **Configuration:** - Added SMTP configuration to telegram-bot .env.example - Added AUTH_SESSION_SECRET to backend .env.example - Updated .gitignore: exclude temporary files (*.pid, *.checksum, test scripts) **Dependencies:** - Added aiosmtplib for async SMTP email sending 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
ROA Reports Backend API
FastAPI backend pentru aplicația de rapoarte ROA2WEB.
🚀 Funcționalități
📊 API Endpoints Implementate
Authentication (/auth)
POST /auth/login- Autentificare utilizatorPOST /auth/logout- Deconectare utilizatorGET /auth/me- Informații utilizator curentGET /auth/validate- Validare token JWT
Companies (/companies)
GET /companies/- Lista firmelor utilizatoruluiGET /companies/{company_code}- Detalii firmăGET /companies/{company_code}/validate- Validare acces firmă
Invoices (/invoices)
GET /invoices/- Lista facturi cu filtrare și paginareGET /invoices/summary- Rezumat facturi pentru dashboardGET /invoices/{invoice_number}- Detalii factură specificăGET /invoices/export/{format}- Export facturi (planned)
Payments (/payments)
GET /payments/- Lista încasări/plăți cu filtrare și paginareGET /payments/summary- Rezumat încasări pentru dashboardGET /payments/{payment_number}- Detalii încasare specificăPOST /payments/- Creare încasare nouă (planned)PUT /payments/{payment_number}- Actualizare încasare (planned)GET /payments/export/{format}- Export încasări (planned)
Health Check
GET /- Status APIGET /health- Health check complet cu database
🏗️ Arhitectură
Shared Components Integration
- Database Pool: Folosește
roa2web/shared/database/oracle_pool.py - JWT Authentication: Folosește
roa2web/shared/auth/pentru validare token-uri - Middleware: Authentication middleware cu rate limiting
Structură Aplicație
app/
├── main.py # FastAPI entry point
├── models/ # Pydantic models
│ ├── invoice.py # Modele pentru facturi
│ └── payment.py # Modele pentru încasări
├── routers/ # API endpoints
│ ├── auth.py # Authentication endpoints
│ ├── companies.py # Companies management
│ ├── invoices.py # Invoices API
│ └── payments.py # Payments API
├── services/ # Business logic
│ ├── invoice_service.py # Serviciu facturi cu Oracle queries
│ └── payment_service.py # Serviciu încasări cu Oracle queries
└── schemas/ # Response schemas (reserved)
🔧 Instalare și Rulare
Development Local
- Install dependencies:
pip install -r requirements.txt
- Environment Variables:
cp .env.example .env
# Editează .env cu configurările tale
- Run development server:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
- Access API:
- API: http://localhost:8000
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Docker
# Build image
docker build -t roa-reports-backend .
# Run container
docker run -p 8000:8000 --env-file .env roa-reports-backend
📝 Configurație
🔐 Oracle Database Setup
IMPORTANT: Conectare la schema CONTAFIN_ORACLE pentru authentication!
Arhitectura Bazei de Date
- Schema CONTAFIN_ORACLE: Conține utilizatorii și procedura
pack_drepturi.verificautilizator - Scheme separate pentru firme: Fiecare firmă are propria schemă cu date (ROMFAST, EUROLEVIS, etc.)
Flow-ul de Autentificare
- Conectare: La schema
CONTAFIN_ORACLE - Verificare: User/pass prin
pack_drepturi.verificautilizator(username, password) - Drepturi: Citire firme din
vdef_util_grup WHERE id_util = user_id - Selecție: User selectează firma/schema pentru acces la date
Environment Variables
# Oracle Database (prin SSH tunnel)
ORACLE_USER=CONTAFIN_ORACLE
ORACLE_PASSWORD=your_oracle_password
ORACLE_HOST=localhost
ORACLE_PORT=1521
ORACLE_SID=ROA
# SSH Tunnel Setup Required:
# ./ssh_tunnel.sh start
# Server: 83.103.197.79:22122 -> 10.0.20.36:1521
# Test User Credentials (pentru dezvoltare):
# Username: "MARIUS M" (cu spațiu în nume!)
# Password: "PAROLA81"
# Are acces la 66+ firme/scheme Oracle
# JWT Settings
JWT_SECRET_KEY=your-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=30
# API Settings
API_HOST=0.0.0.0
API_PORT=8000
DEBUG=True
# CORS
FRONTEND_URLS=http://localhost:3000,http://localhost:5173
🔐 Autentificare
API-ul folosește JWT Bearer tokens pentru autentificare:
- Login:
POST /auth/logincu username/password - Token Usage: Include
Authorization: Bearer <token>în header - Company Access: Fiecare request verifică dacă utilizatorul are acces la firma specificată
📊 Models și Filtrare
Invoice Filter Parameters
company: Codul firmei (obligatoriu)partner_type: CLIENTI sau FURNIZORIdate_from,date_to: Filtrare după datăpartner_name: Filtrare după numele parteneruluionly_unpaid: Doar facturile neachitatemin_amount,max_amount: Filtrare după sumăpage,page_size: Paginare
Response Models
- InvoiceListResponse: Lista paginată cu metadata
- InvoiceSummary: Statistici pentru dashboard
- PaymentListResponse: Lista încasări cu metadata
- PaymentSummary: Statistici încasări
🚀 Următorii Pași
- Export Functionality: Implementare export Excel, PDF, CSV
- CRUD Operations: Operațiuni complete pentru încasări
- Advanced Filtering: Filtre avansate și sortare
- Caching: Redis cache pentru performance
- Rate Limiting: Advanced rate limiting
- Audit Logging: Logging complet pentru operațiuni
🧪 Testing
# Unit tests (când vor fi implementate)
pytest tests/ -v
# Health check manual
curl http://localhost:8000/health
# API testing
# Vezi documentația Swagger la /docs pentru toate endpoint-urile
📚 Compatibilitate
API-ul este compatibil 100% cu query-urile și datele din aplicația Flask existentă:
- Stesso schema de date Oracle
- Aceleași view-uri (
vireg_parteneri) - Aceleași calcule pentru statusul facturilor
- Aceleași validări pentru acces utilizatori
Status: ✅ COMPLET - Ready for Frontend Integration Next Phase: Frontend Vue.js Development