updated web select

This commit is contained in:
2025-04-06 21:52:04 +03:00
parent eef5982e03
commit e4d50306ac
9 changed files with 266 additions and 26 deletions

View File

@@ -296,6 +296,7 @@ def authentication_token_check_post(
"domain": domain or "",
"eys-ext": f"{str(uuid.uuid4())}",
"token": token,
"tz": tz or "GMT+3",
}
if not domain or not language:
return JSONResponse(
@@ -303,10 +304,15 @@ def authentication_token_check_post(
status_code=status.HTTP_406_NOT_ACCEPTABLE,
headers=headers,
)
if AuthHandlers.LoginHandler.authentication_check_token_valid(access_token=token):
return JSONResponse(
content={"message": "MSG_0001"},
status_code=status.HTTP_202_ACCEPTED,
headers=headers,
)
return JSONResponse(
content={},
status_code=status.HTTP_202_ACCEPTED,
content={"error": "EYS_0033"},
status_code=status.HTTP_406_NOT_ACCEPTABLE,
headers=headers,
)

View File

@@ -601,6 +601,13 @@ class LoginHandler:
token_dict=token_object,
)
@classmethod
def authentication_check_token_valid(cls, access_token: str) -> bool:
redis_handler = RedisHandlers()
if redis_handler.get_object_from_redis(access_token=access_token):
return True
return False
class PasswordHandler:

View File

@@ -130,14 +130,12 @@ class TokenProvider:
AUTH_TOKEN: str = "AUTH_TOKEN"
@classmethod
def process_redis_object(cls, redis_object: Dict[str, Any]) -> TokenDictType:
def convert_redis_object_to_token(
cls, redis_object: Dict[str, Any]
) -> TokenDictType:
"""
Process Redis object and return appropriate token object.
"""
if not redis_object.get("selected_company"):
redis_object["selected_company"] = None
if not redis_object.get("selected_occupant"):
redis_object["selected_occupant"] = None
if redis_object.get("user_type") == UserType.employee.value:
return EmployeeTokenObject(**redis_object)
elif redis_object.get("user_type") == UserType.occupant.value:
@@ -160,12 +158,14 @@ class TokenProvider:
if token:
result = RedisActions.get_json(list_keys=auth_key_list, limit=1)
if first_record := result.first:
return cls.process_redis_object(first_record)
return cls.convert_redis_object_to_token(first_record)
elif user_uu_id:
result = RedisActions.get_json(list_keys=auth_key_list)
if all_records := result.all:
for all_record in all_records:
list_of_token_dict.append(cls.process_redis_object(all_record))
list_of_token_dict.append(
cls.convert_redis_object_to_token(all_record)
)
return list_of_token_dict
raise ValueError(
"Token not found in Redis. Please check the token or user_uu_id."
@@ -181,6 +181,8 @@ class TokenProvider:
elif isinstance(tokens, list):
retrieved_event_apps = []
for token in tokens:
if not isinstance(token, TokenDictType):
continue
if application_codes := token.reachable_app_codes.get(page_url, None):
retrieved_event_apps.append(application_codes)
return retrieved_event_apps
@@ -196,10 +198,9 @@ class TokenProvider:
elif isinstance(tokens, List):
retrieved_event_codes = []
for token in tokens:
if isinstance(token, TokenDictType):
if event_codes := token.reachable_event_codes.get(
endpoint_code, None
):
retrieved_event_codes.append(event_codes)
if not isinstance(token, TokenDictType):
continue
if event_codes := token.reachable_event_codes.get(endpoint_code, None):
retrieved_event_codes.append(event_codes)
return retrieved_event_codes
raise ValueError("Invalid token type or no event codes found.")