HTTPException is not returned, raised instead
This commit is contained in:
@@ -44,7 +44,7 @@ if configGet("registration_requires_confirmation") is True:
|
||||
async def user_confirm(user: str, code: str):
|
||||
confirm_record = col_emails.find_one( {"user": user, "code": code, "used": False} )
|
||||
if confirm_record is None:
|
||||
return HTTPException(HTTP_400_BAD_REQUEST, detail=configGet("email_code_invalid", "messages"))
|
||||
raise HTTPException(HTTP_400_BAD_REQUEST, detail=configGet("email_code_invalid", "messages"))
|
||||
col_emails.find_one_and_update( {"_id": confirm_record["_id"]}, {"$set": {"used": True}} )
|
||||
col_users.find_one_and_update( {"user": confirm_record["user"]}, {"$set": {"disabled": False}} )
|
||||
return UJSONResponse( {"detail": configGet("email_confirmed", "messages")} )
|
||||
@@ -53,7 +53,7 @@ if configGet("registration_enabled") is True:
|
||||
@app.post("/users")
|
||||
async def user_create(user: str = Form(), email: str = Form(), password: str = Form()):
|
||||
if col_users.find_one( {"user": user} ) is not None:
|
||||
return HTTPException(HTTP_406_NOT_ACCEPTABLE, detail=configGet("user_already_exists", "messages"))
|
||||
raise HTTPException(HTTP_406_NOT_ACCEPTABLE, detail=configGet("user_already_exists", "messages"))
|
||||
col_users.insert_one( {"user": user, "email": email, "hash": get_password_hash(password), "disabled": configGet("registration_requires_confirmation")} )
|
||||
if configGet("registration_requires_confirmation") is True:
|
||||
scheduler.add_job( send_confirmation, trigger="date", run_date=datetime.now()+timedelta(seconds=1), kwargs={"user": user, "email": email} )
|
||||
@@ -66,7 +66,7 @@ async def user_delete(password: str = Form(), current_user: User = Depends(get_c
|
||||
if not user:
|
||||
return False
|
||||
if not verify_password(password, user.hash):
|
||||
return HTTPException(HTTP_400_BAD_REQUEST, detail=configGet("credentials_invalid", "messages"))
|
||||
raise HTTPException(HTTP_400_BAD_REQUEST, detail=configGet("credentials_invalid", "messages"))
|
||||
col_users.delete_many( {"user": current_user.user} )
|
||||
col_emails.delete_many( {"user": current_user.user} )
|
||||
col_photos.delete_many( {"user": current_user.user} )
|
||||
|
Reference in New Issue
Block a user