feat: Update endpoint login
This commit is contained in:
parent
b92e35db55
commit
fb95c3fc5f
@ -1,7 +1,26 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from typing import Optional
|
||||||
|
from models import User
|
||||||
|
from schemas import UserCreate
|
||||||
|
from database import get_db
|
||||||
|
from utils import hash_password
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/login")
|
@router.post("/signup", response_model=UserCreate, status_code=status.HTTP_201_CREATED)
|
||||||
async def login(username: str, password: str):
|
async def create_user(user: UserCreate, db: Session = Depends(get_db)):
|
||||||
return {"message": "User logged in successfully", "username": username}
|
"""
|
||||||
|
Create a new user account
|
||||||
|
"""
|
||||||
|
existing_user = db.query(User).filter(User.email == user.email).first()
|
||||||
|
if existing_user:
|
||||||
|
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail="Email already registered")
|
||||||
|
|
||||||
|
hashed_password = hash_password(user.password)
|
||||||
|
new_user = User(email=user.email, hashed_password=hashed_password)
|
||||||
|
db.add(new_user)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(new_user)
|
||||||
|
|
||||||
|
return new_user
|
Loading…
x
Reference in New Issue
Block a user