def authenticate_user(user: schemas.UserAuthenticate, db: Session = Depends(get_db)): db_user = crud.get_user_by_username(db, username=user.username) if db_user is None: raise HTTPException(status_code=400, detail="Username not existed") else: is_password_correct = crud.check_username_password(db, user) if is_password_correct is False: raise HTTPException(status_code=400, detail="Password is not correct") else: from datetime import timedelta access_token_expires = timedelta( minutes=ACCESS_TOKEN_EXPIRE_MINUTES) from sql_app.app_utils import create_access_token access_token = create_access_token( data={"sub": user.username}, expires_delta=access_token_expires) return {"access_token": access_token, "token_type": "Bearer"}
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)): db_user = crud.get_user_by_username(db, username=user.username) if db_user: raise HTTPException(status_code=400, detail="Username already registered") return crud.create_user(db=db, user=user)
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)): db_user = crud.get_user_by_username(db, username=user.username) if not db_user: raise HTTPException(status_code=400, detail="Username Not Found") return db_user