46 lines
1.3 KiB
Python
46 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 RegistrationData(BaseModel):
|
|
username: str
|
|
email: EmailStr
|
|
password: str
|
|
full_name: str
|
|
|
|
@router.post("/register")
|
|
async def register_user(data: RegistrationData):
|
|
"""Register new user endpoint"""
|
|
if data.username in fake_users_db:
|
|
raise HTTPException(status_code=400, detail="Username already exists")
|
|
|
|
if any(user["email"] == data.email for user in fake_users_db.values()):
|
|
raise HTTPException(status_code=400, detail="Email already registered")
|
|
|
|
user_id = str(uuid.uuid4())
|
|
fake_users_db[data.username] = {
|
|
"id": user_id,
|
|
"email": data.email,
|
|
"password": data.password,
|
|
"full_name": data.full_name,
|
|
"disabled": False,
|
|
"created_at": str(uuid.uuid1())
|
|
}
|
|
|
|
return {
|
|
"message": "Registration successful",
|
|
"user_id": user_id,
|
|
"username": data.username,
|
|
"next_steps": [
|
|
"Verify your email address",
|
|
"Complete your profile",
|
|
"Set up two-factor authentication"
|
|
],
|
|
"features": {
|
|
"rate_limit": 50,
|
|
"expires_in": 3600
|
|
}
|
|
} |