energensy contacts, dashboard
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -9,6 +9,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.openapi.utils import get_openapi
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Any
|
||||
|
||||
from shared.config import settings
|
||||
from services.user_service.schemas import UserCreate, UserLogin, UserResponse, UserUpdate, Token
|
||||
@@ -248,7 +249,17 @@ async def register_user(user_create: UserCreate, request: Request):
|
||||
async def login_user(user_login: UserLogin, request: Request):
|
||||
"""Login user"""
|
||||
client_ip = get_client_ip(request)
|
||||
|
||||
# Дополнительное логирование для отладки
|
||||
try:
|
||||
request_body = await request.body()
|
||||
print(f"RAW request body from {client_ip}: {request_body}")
|
||||
print(f"Request headers: {dict(request.headers)}")
|
||||
except:
|
||||
pass
|
||||
|
||||
print(f"Login request from {client_ip}: {user_login.model_dump(exclude={'password'})}")
|
||||
print(f"Full login data: {user_login.model_dump()}")
|
||||
|
||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||
try:
|
||||
@@ -312,6 +323,113 @@ async def login_user(user_login: UserLogin, request: Request):
|
||||
raise HTTPException(status_code=500, detail=f"Login error: {str(e)}")
|
||||
|
||||
|
||||
# Debug endpoint to analyze raw request data
|
||||
@app.post("/api/v1/debug/login", tags=["Debug"], summary="Debug login request data")
|
||||
async def debug_login_request(request: Request):
|
||||
"""Debug endpoint to analyze raw request data from mobile app"""
|
||||
try:
|
||||
client_ip = get_client_ip(request)
|
||||
headers = dict(request.headers)
|
||||
body = await request.body()
|
||||
|
||||
debug_info = {
|
||||
"client_ip": client_ip,
|
||||
"headers": headers,
|
||||
"raw_body": body.decode('utf-8', errors='ignore') if body else None,
|
||||
"content_length": len(body) if body else 0,
|
||||
"content_type": headers.get('content-type', 'unknown')
|
||||
}
|
||||
|
||||
print(f"DEBUG LOGIN from {client_ip}:")
|
||||
print(f"Headers: {headers}")
|
||||
print(f"Raw body: {body}")
|
||||
|
||||
# Try to parse as JSON
|
||||
try:
|
||||
if body:
|
||||
import json
|
||||
json_data = json.loads(body)
|
||||
debug_info["parsed_json"] = json_data
|
||||
print(f"Parsed JSON: {json_data}")
|
||||
except Exception as e:
|
||||
debug_info["json_parse_error"] = str(e)
|
||||
print(f"JSON parse error: {e}")
|
||||
|
||||
return debug_info
|
||||
|
||||
except Exception as e:
|
||||
print(f"Debug endpoint error: {str(e)}")
|
||||
return {"error": str(e)}
|
||||
|
||||
|
||||
# Alternative login endpoint for mobile app debugging
|
||||
@app.post("/api/v1/auth/login-flexible", tags=["Authentication"], summary="Flexible login for debugging")
|
||||
async def login_flexible(request: Request):
|
||||
"""Flexible login endpoint that accepts various data formats"""
|
||||
try:
|
||||
client_ip = get_client_ip(request)
|
||||
body = await request.body()
|
||||
|
||||
print(f"Flexible login from {client_ip}")
|
||||
print(f"Raw request: {body}")
|
||||
|
||||
# Try to parse JSON
|
||||
import json
|
||||
try:
|
||||
data = json.loads(body) if body else {}
|
||||
except:
|
||||
return {"error": "Invalid JSON format", "status": 422}
|
||||
|
||||
print(f"Parsed data: {data}")
|
||||
|
||||
# Extract login fields with flexible names
|
||||
email = data.get('email') or data.get('Email') or data.get('EMAIL')
|
||||
username = data.get('username') or data.get('Username') or data.get('user_name') or data.get('login')
|
||||
password = data.get('password') or data.get('Password') or data.get('PASSWORD') or data.get('pass')
|
||||
|
||||
print(f"Extracted: email={email}, username={username}, password={'***' if password else None}")
|
||||
|
||||
# Validation
|
||||
if not password:
|
||||
return {"error": "Password is required", "status": 422}
|
||||
|
||||
if not email and not username:
|
||||
return {"error": "Either email or username must be provided", "status": 422}
|
||||
|
||||
# Create proper login data
|
||||
login_data = {
|
||||
"email": email,
|
||||
"username": username,
|
||||
"password": password
|
||||
}
|
||||
|
||||
# Forward to user service
|
||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||
response = await client.post(
|
||||
f"{SERVICES['users']}/api/v1/auth/login",
|
||||
json=login_data,
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
}
|
||||
)
|
||||
|
||||
print(f"User service response: {response.status_code} - {response.text}")
|
||||
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
try:
|
||||
error_data = response.json()
|
||||
return {"error": error_data.get("detail", "Login failed"), "status": response.status_code}
|
||||
except:
|
||||
return {"error": response.text, "status": response.status_code}
|
||||
|
||||
except Exception as e:
|
||||
print(f"Flexible login error: {str(e)}")
|
||||
return {"error": str(e), "status": 500}
|
||||
|
||||
|
||||
# Utility endpoints
|
||||
@app.get("/api/v1/auth/check-email", tags=["Authentication"], summary="Check if email is available")
|
||||
async def check_email_availability(email: str):
|
||||
|
||||
Reference in New Issue
Block a user