alchemy flush and save functions updated
This commit is contained in:
parent
1f1222c32d
commit
f6135ced5f
|
|
@ -50,7 +50,6 @@ def save_access_token_to_redis(
|
|||
Employees,
|
||||
Staff,
|
||||
)
|
||||
print('save_access_token_to_redis')
|
||||
if not found_user:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
|
|
@ -58,10 +57,8 @@ def save_access_token_to_redis(
|
|||
# headers=json.loads(json.dumps(request.headers)),
|
||||
)
|
||||
|
||||
print('save_access_token_to_redis', found_user)
|
||||
# Check user is already logged in or has a previous session
|
||||
already_tokens = get_object_via_user_uu_id(user_id=found_user.uu_id)
|
||||
print('already_tokens', already_tokens)
|
||||
for key in already_tokens or []:
|
||||
token_user = json.loads(redis_cli.get(key).decode() or {})
|
||||
if token_user.get("domain", "") == domain:
|
||||
|
|
@ -70,7 +67,6 @@ def save_access_token_to_redis(
|
|||
access_token = (
|
||||
found_user.generate_access_token() if not access_token else access_token
|
||||
)
|
||||
print('access_token', access_token)
|
||||
# Prepare the user's details to save in Redis Session
|
||||
if found_user.is_occupant: # Check if user is NOT an occupant
|
||||
living_spaces: list[BuildLivingSpace] = BuildLivingSpace.filter_all(
|
||||
|
|
@ -84,7 +80,6 @@ def save_access_token_to_redis(
|
|||
),
|
||||
# headers=json.loads(json.dumps(request.headers)),
|
||||
)
|
||||
print('living_spaces', living_spaces)
|
||||
occupants_selection_dict = {}
|
||||
for living_space in living_spaces:
|
||||
build_parts_selection = BuildParts.filter_active(
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ def get_object_via_access_key(
|
|||
already_tokens = redis_cli.scan_iter(
|
||||
match=str(request.headers.get(Auth.ACCESS_TOKEN_TAG) + ":*")
|
||||
)
|
||||
print('already_tokens', already_tokens)
|
||||
|
||||
if already_tokens := list(already_tokens):
|
||||
try:
|
||||
if redis_object := json.loads(
|
||||
|
|
|
|||
|
|
@ -161,9 +161,8 @@ class AuthModule(PasswordModule):
|
|||
found_user.password_expiry_begins = str(system_arrow.now())
|
||||
found_user.hash_password = new_password_dict.get("password")
|
||||
found_user.password_token = "" if found_user.password_token else ""
|
||||
found_user.save()
|
||||
query_engine.refresh_password_history_via_user(payload=history_dict)
|
||||
return
|
||||
return found_user.save()
|
||||
|
||||
@staticmethod
|
||||
def reset_password_token(found_user):
|
||||
|
|
|
|||
|
|
@ -79,7 +79,6 @@ class MongoQueryIdentity:
|
|||
hashed_password = payload.password_add.get("password")
|
||||
for password_in_history in password_history_list:
|
||||
if str(password_in_history.get("password")) == str(hashed_password):
|
||||
print('Password already used. Please enter a new password that you have not used last 3 times.')
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Password already used. Please enter a new password that you have not used last 3 times.",
|
||||
|
|
@ -89,7 +88,7 @@ class MongoQueryIdentity:
|
|||
password_history_list.pop(0)
|
||||
|
||||
password_history_list.append(payload.password_add)
|
||||
self.mongo_engine.update(
|
||||
return self.mongo_engine.update(
|
||||
match=payload.user_uu_id,
|
||||
payload={
|
||||
"password_history": password_history_list,
|
||||
|
|
@ -98,7 +97,6 @@ class MongoQueryIdentity:
|
|||
},
|
||||
field="user_uu_id",
|
||||
)
|
||||
return True
|
||||
|
||||
def get_password_history_via_user(self, user_uu_id):
|
||||
self.use_collection("PasswordHistory")
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ class MongoQuery:
|
|||
return self.table.insert_many(documents=[payload])
|
||||
|
||||
def update(self, match, payload, field: str = "id"):
|
||||
print('update', match, payload, field)
|
||||
if field == "id":
|
||||
filter_ = {"_id": ObjectId(match)}
|
||||
self.table.update_one(filter=filter_, update={"$set": payload})
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ class FilterAttributes:
|
|||
FilterModel = ListOptions
|
||||
|
||||
def flush(self):
|
||||
from fastapi import status
|
||||
"""Flush the current session."""
|
||||
try:
|
||||
self.__session__.add(self)
|
||||
self.__session__.flush()
|
||||
return self
|
||||
except SQLAlchemyError as e:
|
||||
self.raise_http_exception(
|
||||
status_code="HTTP_400_BAD_REQUEST",
|
||||
|
|
@ -47,6 +47,7 @@ class FilterAttributes:
|
|||
"""Saves the updated model to the current entity db."""
|
||||
try:
|
||||
cls.__session__.commit()
|
||||
return cls
|
||||
except SQLAlchemyError as e:
|
||||
cls.raise_http_exception(
|
||||
status_code="HTTP_400_BAD_REQUEST",
|
||||
|
|
|
|||
Loading…
Reference in New Issue