Update code in endpoints/api/v1/endpoint.post.py
This commit is contained in:
parent
79295be0fd
commit
f8ac869eb1
48
endpoints/api/v1/endpoint.post.py
Normal file
48
endpoints/api/v1/endpoint.post.py
Normal file
@ -0,0 +1,48 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from core.database import fake_users_db
|
||||
import uuid
|
||||
import random
|
||||
import string
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/signup-codes")
|
||||
async def generate_signup_codes(
|
||||
count: int = 1,
|
||||
length: int = 8,
|
||||
prefix: str = ""
|
||||
):
|
||||
"""Generate unique signup invitation codes"""
|
||||
codes = []
|
||||
existing_codes = [user.get("signup_code") for user in fake_users_db.values()]
|
||||
|
||||
for _ in range(count):
|
||||
while True:
|
||||
code = prefix + ''.join(random.choices(
|
||||
string.ascii_uppercase + string.digits,
|
||||
k=length
|
||||
))
|
||||
if code not in existing_codes:
|
||||
codes.append(code)
|
||||
break
|
||||
|
||||
# Store codes in database for future validation
|
||||
batch_id = str(uuid.uuid4())
|
||||
for code in codes:
|
||||
fake_users_db[f"signup_code_{code}"] = {
|
||||
"code": code,
|
||||
"batch_id": batch_id,
|
||||
"used": False,
|
||||
"created_at": "2024-01-01T00:00:00Z" # Demo timestamp
|
||||
}
|
||||
|
||||
return {
|
||||
"message": f"Successfully generated {count} signup codes",
|
||||
"batch_id": batch_id,
|
||||
"codes": codes,
|
||||
"metadata": {
|
||||
"prefix": prefix,
|
||||
"length": length,
|
||||
"expires_in": "30 days"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user