migrator functions updated

This commit is contained in:
2024-11-11 22:23:07 +03:00
parent f6135ced5f
commit ffb85a62f6
56 changed files with 567 additions and 485 deletions

View File

@@ -44,12 +44,13 @@ class AuthModule(PasswordModule):
@classmethod
def check_user_exits(cls, access_key, domain):
found_user = cls.filter_one(
from databases import Users
found_user = Users.query.filter(
or_(
cls.email == str(access_key).lower(),
cls.phone_number == str(access_key).replace(" ", ""),
Users.email == str(access_key).lower(),
Users.phone_number == str(access_key).replace(" ", ""),
),
).data
).first()
if not found_user:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
@@ -73,6 +74,7 @@ class AuthModule(PasswordModule):
from databases import (
UsersTokens,
)
if disconnect:
registered_tokens = UsersTokens.filter_all(
UsersTokens.user_id == self.id, system=True
@@ -88,19 +90,12 @@ class AuthModule(PasswordModule):
def check_password(self, password):
main_domain = self.get_main_domain_and_other_domains(get_main_domain=True)
print('check_password', dict(
domain=main_domain,
id_=str(self.uu_id),
password_hashed=self.hash_password,
password=password,
))
if check_password := self.check_hashed_password(
domain=main_domain,
id_=str(self.uu_id),
password_hashed=self.hash_password,
password=password,
):
print('check_password', check_password)
return check_password
raise HTTPException(
status_code=401,
@@ -120,6 +115,7 @@ class AuthModule(PasswordModule):
@staticmethod
def create_password(found_user, password, password_token=None):
from databases import MongoQueryIdentity
if found_user.password_token:
replace_day = 0
try:
@@ -141,9 +137,9 @@ class AuthModule(PasswordModule):
)
query_engine = MongoQueryIdentity(company_uuid=found_user.related_company)
domain_via_user = query_engine.get_domain_via_user(user_uu_id=str(found_user.uu_id))[
"main_domain"
]
domain_via_user = query_engine.get_domain_via_user(
user_uu_id=str(found_user.uu_id)
)["main_domain"]
new_password_dict = {
"password": found_user.create_hashed_password(
domain=domain_via_user, id_=str(found_user.uu_id), password=password
@@ -167,18 +163,21 @@ class AuthModule(PasswordModule):
@staticmethod
def reset_password_token(found_user):
found_user.password_expiry_begins = str(system_arrow.now())
found_user.password_token = found_user.generate_token(127)
found_user.password_token = found_user.generate_token(
Auth.REFRESHER_TOKEN_LENGTH
)
found_user.save()
def generate_refresher_token(self, domain: str, remember_me=False):
from databases import (
UsersTokens,
)
if remember_me:
refresh_token = self.generate_token(Auth.REFRESHER_TOKEN_LENGTH)
if already_token := UsersTokens.find_one(
user_id=self.id, token_type="RememberMe", domain=domain
):
if already_token := UsersTokens.filter_by_one(
system=True, user_id=self.id, token_type="RememberMe", domain=domain
).data:
already_token.update(token=refresh_token)
already_token.expires_at = system_arrow.shift(days=3)
already_token.save()
@@ -194,16 +193,13 @@ class AuthModule(PasswordModule):
return None
def remainder_day(self):
join_list = [
_ for _ in str(self.password_expires_day).split(",")[0] if _.isdigit()
]
return float(
timedelta(
days=int(
"".join(
[
_
for _ in str(self.password_expires_day).split(",")[0]
if _.isdigit()
]
)
"".join(join_list)
)
).seconds
)
@@ -218,13 +214,13 @@ class UserLoginModule(AuthModule):
People,
MongoQueryIdentity,
)
found_user = Users.check_user_exits(
access_key=data.access_key, domain=data.domain
)
access_token = found_user.generate_access_token()
query_engine = MongoQueryIdentity(company_uuid=found_user.related_company)
if found_user.check_password(password=data.password):
print('before access_object_to_redis')
access_object_to_redis = save_access_token_to_redis(
request=request,
found_user=found_user,
@@ -270,7 +266,9 @@ class UserLoginModule(AuthModule):
no_address_validates = mongo_db.mongo_engine.get_all()[0] == 0
record_id = uuid.uuid4().__str__()
notice_link = ApiStatic.blacklist_login(record_id=record_id)
found_people = People.find_one(id=found_user.person_id)
found_people = People.filter_one(
People.id == found_user.person_id, *People.valid_record_args(People)
).data
access_via_user = query_engine.update_access_history_via_user(
AccessHistoryViaUser(
**{