Update code in endpoints/api/v1/endpoint.post.py
This commit is contained in:
parent
5a2b25e252
commit
94448f1db1
45
endpoints/api/v1/endpoint.post.py
Normal file
45
endpoints/api/v1/endpoint.post.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from core.database import fake_users_db
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/signup")
|
||||||
|
async def signup_handler(
|
||||||
|
username: str,
|
||||||
|
email: str,
|
||||||
|
password: str
|
||||||
|
):
|
||||||
|
"""Create new user account"""
|
||||||
|
if username in fake_users_db:
|
||||||
|
raise HTTPException(status_code=400, detail="Username already exists")
|
||||||
|
|
||||||
|
if not email or '@' not in email:
|
||||||
|
raise HTTPException(status_code=400, detail="Invalid email format")
|
||||||
|
|
||||||
|
if len(password) < 8:
|
||||||
|
raise HTTPException(status_code=400, detail="Password must be at least 8 characters")
|
||||||
|
|
||||||
|
user_id = str(uuid.uuid4())
|
||||||
|
fake_users_db[username] = {
|
||||||
|
"id": user_id,
|
||||||
|
"email": email,
|
||||||
|
"password": password,
|
||||||
|
"disabled": False,
|
||||||
|
"created_at": str(uuid.uuid1())
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "User created successfully",
|
||||||
|
"user_id": user_id,
|
||||||
|
"username": username,
|
||||||
|
"next_steps": [
|
||||||
|
"Verify your email address",
|
||||||
|
"Complete your profile",
|
||||||
|
"Set up two-factor authentication"
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"account_status": "pending_verification",
|
||||||
|
"created_timestamp": fake_users_db[username]["created_at"]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user