Skip to content

Commit

Permalink
add token with user
Browse files Browse the repository at this point in the history
  • Loading branch information
Leg0shii committed Sep 29, 2024
1 parent ac1a24e commit 07eb01c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
22 changes: 1 addition & 21 deletions backend/app/routers/users.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# backend/app/routers/users.py
from app.database import get_db
from app.models import User
from app.schemas import UserCreate, UserResponse
from app.utils import hash_password
from app.schemas import UserResponse
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session

Expand All @@ -12,25 +11,6 @@
)


@router.post("/", response_model=UserResponse)
def create_user(user: UserCreate, db: Session = Depends(get_db)):
db_user = (
db.query(User)
.filter((User.username == user.username) | (User.email == user.email))
.first()
)
if db_user:
raise HTTPException(
status_code=400, detail="Username or email already registered"
)
hashed_pw = hash_password(user.password)
new_user = User(username=user.username, email=user.email, hashed_password=hashed_pw)
db.add(new_user)
db.commit()
db.refresh(new_user)
return new_user


@router.get("/{user_id}", response_model=UserResponse)
def get_user(user_id: int, db: Session = Depends(get_db)):
user = db.query(User).filter(User.id == user_id).first()
Expand Down
4 changes: 4 additions & 0 deletions backend/app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,7 @@ class TokenData(BaseModel):
class UserLogin(BaseModel):
username: str
password: str


class TokenWithUser(Token):
user: UserResponse

0 comments on commit 07eb01c

Please sign in to comment.