alchemy flush and save functions updated

This commit is contained in:
2024-11-11 18:55:53 +03:00
parent c42a19c262
commit 1f1222c32d
163 changed files with 6296 additions and 476 deletions

View File

@@ -64,7 +64,6 @@ class AuthenticationLoginEventMethods(MethodToEvent):
cls,
data: Login,
request,
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
):
access_dict = Users.login_user_with_credentials(data=data, request=request)
found_user = access_dict.get("user", None)
@@ -377,40 +376,40 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
raise HTTPException(
status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match"
)
if found_user := Users.filter_one(
found_user = Users.filter_one(
Users.password_token == data.password_token,
*Users.valid_record_args(Users),
).data:
found_user.create_password(password=data.password)
found_user.password_token = None
found_user.save()
send_email_completed = send_email(
subject=f"Dear {found_user.user_tag}, your password has been changed.",
receivers=[str(found_user.email)],
html=password_is_changed_template(user_name=found_user.user_tag),
)
if not send_email_completed:
raise HTTPException(
status_code=400, detail="Email can not be sent. Try again later"
)
).data
if not found_user:
return JSONResponse(
content={
"completed": True,
"message": "Password is created successfully",
"data": found_user.get_dict(),
"completed": False,
"message": "Record not found",
"data": {},
},
status_code=status.HTTP_200_OK,
status_code=status.HTTP_202_ACCEPTED,
)
found_user.create_password(found_user=found_user,password=data.password)
# send_email_completed = send_email(
# subject=f"Dear {found_user.user_tag}, your password has been changed.",
# receivers=[str(found_user.email)],
# html=password_is_changed_template(user_name=found_user.user_tag),
# )
# if not send_email_completed:
# raise HTTPException(
# status_code=400, detail="Email can not be sent. Try again later"
# )
return JSONResponse(
content={
"completed": False,
"message": "Record not found",
"data": {},
"completed": True,
"message": "Password is created successfully",
"data": found_user.get_dict(),
},
status_code=status.HTTP_202_ACCEPTED,
status_code=status.HTTP_200_OK,
)
class AuthenticationDisconnectUserEventMethods(MethodToEvent):
event_type = "UPDATE"