Improve auth models

This commit is contained in:
Urtzi Alfaro
2025-07-19 21:16:25 +02:00
parent abc8b68ab4
commit c7fd6135f0
9 changed files with 382 additions and 120 deletions

View File

@@ -39,9 +39,6 @@ class AuthService:
detail="Email already registered"
)
# Generate tenant_id if not provided
tenant_id = user_data.tenant_id if hasattr(user_data, 'tenant_id') and user_data.tenant_id else str(uuid.uuid4())
# Hash password
hashed_password = security_manager.hash_password(user_data.password)
@@ -49,7 +46,6 @@ class AuthService:
user = User(
email=user_data.email,
hashed_password=hashed_password,
tenant_id=tenant_id,
full_name=user_data.full_name,
phone=user_data.phone,
language=user_data.language,

View File

@@ -7,6 +7,7 @@ from sqlalchemy import select, update, delete
from fastapi import HTTPException, status
from passlib.context import CryptContext
import structlog
from datetime import datetime, timezone
from app.models.users import User
from app.core.config import settings
@@ -59,6 +60,7 @@ class UserService:
update_data[field] = user_data[field]
if update_data:
update_data["updated_at"] = datetime.now(timezone.utc)
await db.execute(
update(User)
.where(User.id == user_id)
@@ -107,7 +109,7 @@ class UserService:
await db.execute(
update(User)
.where(User.id == user_id)
.values(hashed_password=new_hashed_password)
.values(hashed_password=new_hashed_password, updated_at=datetime.now(timezone.utc))
)
await db.commit()