mongo updated

This commit is contained in:
2025-01-10 20:52:45 +03:00
parent d8685dd496
commit cecf1e69a2
66 changed files with 3597 additions and 857 deletions

View File

@@ -56,14 +56,41 @@ class MongoQueryIdentity:
return [self.validate_timestamp(doc) for doc in result.data] if result else None
def refresh_password_history_via_user(self, payload: PasswordHistoryViaUser):
self.use_collection("PasswordHistory")
password_history_item = self.mongo_engine.get_one(
match=payload.user_uu_id, field="user_uu_id"
)
if not password_history_item:
self.mongo_engine.insert(
payload={
"user_uu_id": str(payload.user_uu_id),
"password_history": [],
}
)
password_history_item = self.mongo_engine.get_one(
match=payload.user_uu_id, field="user_uu_id"
).data
password_history_list = password_history_item.get("password_history", [])
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):
raise HTTPException(
status_code=400,
detail="Password already used. Please enter a new password that you have not used last 3 times.",
)
if len(password_history_list) > 3:
password_history_list.pop(0)
password_history_list.append(payload.password_add)
return self.mongo_engine.update(
field="user_uu_id",
match=payload.user_uu_id,
payload={
"password_history": payload.password_history,
"password_history": password_history_list,
"access_history_detail": payload.access_history_detail,
"modified_at": system_arrow.to_timestamp(system_arrow.now()),
"modified_at": system_arrow.now().timestamp(),
},
field="user_uu_id",
)
def get_password_history_via_user(self, user_uu_id):
@@ -99,6 +126,7 @@ class MongoQueryIdentity:
result = self.mongo_engine.filter_by(payload={"user_uu_id": user_uu_id})
return [self.validate_timestamp(doc) for doc in result.data] if result else None
@staticmethod
def validate_timestamp(doc):
"""Validate and fix timestamp fields in MongoDB documents"""
if not doc: