From cd713a84b64ee5d5383745665ef94239dca75bad Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sat, 29 Mar 2025 21:57:34 +0000 Subject: [PATCH] Update code in endpoints/signup.post.py --- endpoints/signup.post.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/endpoints/signup.post.py b/endpoints/signup.post.py index 6e3e9b6..2a692ce 100644 --- a/endpoints/signup.post.py +++ b/endpoints/signup.post.py @@ -2,27 +2,22 @@ from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy.orm import Session from core.database import get_db from models.user import User -from schemas.user import UserLogin, UserResponse -from helpers.auth_helpers import authenticate_user, create_access_token +from schemas.user import UserCreate, UserResponse +from helpers.user_helpers import create_user, get_user_by_email router = APIRouter() -@router.post("/signup", status_code=status.HTTP_200_OK, response_model=UserResponse) -async def login( - user_data: UserLogin, +@router.post("/signup", status_code=status.HTTP_201_CREATED, response_model=UserResponse) +async def signup( + user_data: UserCreate, db: Session = Depends(get_db) ): - user = authenticate_user(db, user_data.email, user_data.password) - if not user: + existing_user = get_user_by_email(db, user_data.email) + if existing_user: raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail="Incorrect email or password", - headers={"WWW-Authenticate": "Bearer"}, + status_code=status.HTTP_400_BAD_REQUEST, + detail="Email already registered" ) - access_token = create_access_token(data={"sub": user.email}) - return { - "access_token": access_token, - "token_type": "bearer", - "user": user - } \ No newline at end of file + new_user = create_user(db, user_data) + return new_user \ No newline at end of file