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