async def create_user( request: Request, data: UserAPI, user: Optional[UserAPI] = Depends(get_user)) -> Any: if user is None or user.role != UserRole.super: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Could not validate credentials", headers={"WWW-Authenticate": "Token"}, ) # check if such username exists if User.get(username=data.username): request.session["username_exists"] = f"Such Username already exists!" raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST) data.password = pwd_hash(data.password) data.projects = [ Project.get(id=project_id) for project_id in data.projects ] return UserAPI.parse_obj(User.create(data.dict()).to_dict())
def create(self, request): user = User.create(name=request.get("name"), age=request.get("age")) return Response(data=user)