Update code in endpoints/signup.post.py
This commit is contained in:
parent
2e588ff382
commit
6c75e9e6c4
@ -1,50 +1,35 @@
|
|||||||
from fastapi import APIRouter, HTTPException, Depends
|
from fastapi import APIRouter, HTTPException
|
||||||
from sqlalchemy.orm import Session
|
|
||||||
from pydantic import BaseModel
|
|
||||||
from core.database import get_db
|
|
||||||
from core.auth import get_password_hash, create_access_token
|
|
||||||
import uuid
|
import uuid
|
||||||
from models.user import User
|
|
||||||
|
contacts = [] # In-memory storage
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
class UserCreate(BaseModel):
|
|
||||||
username: str
|
|
||||||
email: str
|
|
||||||
password: str
|
|
||||||
|
|
||||||
@router.post("/signup")
|
@router.post("/signup")
|
||||||
async def signup(
|
async def signup_ngo(
|
||||||
user_data: UserCreate,
|
name: str = "Organization Name",
|
||||||
db: Session = Depends(get_db)
|
email: str = "org@example.com",
|
||||||
|
phone: str = "123-456-7890"
|
||||||
):
|
):
|
||||||
"""User registration endpoint"""
|
"""NGO signup endpoint"""
|
||||||
# Check existing user
|
if any(c["email"] == email for c in contacts):
|
||||||
db_user = db.query(User).filter(
|
raise HTTPException(status_code=400, detail="Email already registered")
|
||||||
(User.username == user_data.username) |
|
|
||||||
(User.email == user_data.email)
|
|
||||||
).first()
|
|
||||||
|
|
||||||
if db_user:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=400,
|
|
||||||
detail="Username or email already exists"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create new user
|
contact_id = str(uuid.uuid4())
|
||||||
new_user = User(
|
contacts.append({
|
||||||
id=str(uuid.uuid4()),
|
"id": contact_id,
|
||||||
username=user_data.username,
|
"name": name,
|
||||||
email=user_data.email,
|
"email": email,
|
||||||
hashed_password=get_password_hash(user_data.password)
|
"phone": phone,
|
||||||
)
|
"status": "pending"
|
||||||
|
})
|
||||||
db.add(new_user)
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
# Return token directly after registration
|
|
||||||
return {
|
return {
|
||||||
"message": "User created successfully",
|
"message": "Contact request submitted successfully",
|
||||||
"access_token": create_access_token({"sub": new_user.id}),
|
"contact_id": contact_id,
|
||||||
"token_type": "bearer"
|
"name": name,
|
||||||
}
|
"next_steps": [
|
||||||
|
"Check email for confirmation",
|
||||||
|
"Schedule orientation call"
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user