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

@@ -1,6 +1,8 @@
import datetime
from fastapi import HTTPException
from api_library.date_time_actions.date_functions import system_arrow
from .validations import PasswordHistoryViaUser, DomainViaUser, AccessHistoryViaUser
from .mongo_database import MongoQuery
@@ -31,6 +33,7 @@ class MongoQueryIdentity:
table_name=self.mongo_collection_name, database_name="mongo_database"
)
def create_domain_via_user(self, payload: DomainViaUser):
self.use_collection("Domain")
return self.mongo_engine.insert(
@@ -69,15 +72,14 @@ class MongoQueryIdentity:
"password_history": [],
}
)
password_history_item = self.mongo_engine.get_one(
match=payload.user_uu_id, field="user_uu_id"
)
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 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(
status_code=400,
detail="Password already used. Please enter a new password that you have not used last 3 times.",
@@ -87,8 +89,7 @@ class MongoQueryIdentity:
password_history_list.pop(0)
password_history_list.append(payload.password_add)
return self.mongo_engine.update(
self.mongo_engine.update(
match=payload.user_uu_id,
payload={
"password_history": password_history_list,
@@ -97,6 +98,7 @@ class MongoQueryIdentity:
},
field="user_uu_id",
)
return True
def get_password_history_via_user(self, user_uu_id):
self.use_collection("PasswordHistory")

View File

@@ -61,6 +61,7 @@ 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})