43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from core.database import fake_users_db
|
|
from pydantic import BaseModel, EmailStr
|
|
import uuid
|
|
|
|
router = APIRouter()
|
|
|
|
class UserRegistration(BaseModel):
|
|
username: str
|
|
email: EmailStr
|
|
password: str
|
|
full_name: str | None = None
|
|
|
|
@router.post("/register")
|
|
async def register_user(user_data: UserRegistration):
|
|
"""Register a new user"""
|
|
if user_data.username in fake_users_db:
|
|
raise HTTPException(status_code=400, detail="Username already exists")
|
|
|
|
user_id = str(uuid.uuid4())
|
|
fake_users_db[user_data.username] = {
|
|
"id": user_id,
|
|
"email": user_data.email,
|
|
"password": user_data.password, # In production, hash this password
|
|
"full_name": user_data.full_name,
|
|
"disabled": False,
|
|
"created_at": str(datetime.now())
|
|
}
|
|
|
|
return {
|
|
"message": "User registered successfully",
|
|
"user_id": user_id,
|
|
"username": user_data.username,
|
|
"next_steps": [
|
|
"Verify your email address",
|
|
"Complete your profile",
|
|
"Set up two-factor authentication"
|
|
],
|
|
"metadata": {
|
|
"account_status": "pending_verification",
|
|
"registration_date": str(datetime.now())
|
|
}
|
|
} |