updated handler exceptions
This commit is contained in:
@@ -13,7 +13,7 @@ from api_services.templates.password_templates import (
|
||||
from api_services.token_service import TokenService
|
||||
from api_services.redis.functions import RedisActions
|
||||
from api_library.response_handlers import ResponseHandler
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
from api_library.date_time_actions.date_functions import system_arrow, DateTimeLocal
|
||||
|
||||
# from api_library.user_logger import UserLogger
|
||||
|
||||
@@ -74,38 +74,41 @@ class AuthenticationLoginEventMethods(MethodToEvent):
|
||||
|
||||
@classmethod
|
||||
def authentication_login_with_domain_and_creds(cls, data: Login, request: Request):
|
||||
try:
|
||||
access_dict = Users.login_user_with_credentials(data=data, request=request)
|
||||
found_user = access_dict.get("user")
|
||||
if not found_user:
|
||||
# UserLogger.log_login_attempt(
|
||||
# request,
|
||||
# None,
|
||||
# data.domain,
|
||||
# data.access_key,
|
||||
# success=False,
|
||||
# error="Invalid credentials",
|
||||
# )
|
||||
return ResponseHandler.unauthorized("Invalid credentials")
|
||||
from api_objects import HTTPExceptionEvyos
|
||||
|
||||
raise HTTPExceptionEvyos(
|
||||
error_code="UNKNOWN_ERROR",
|
||||
lang="en",
|
||||
)
|
||||
access_dict = Users.login_user_with_credentials(data=data, request=request)
|
||||
found_user = access_dict.get("user")
|
||||
Users.client_arrow = DateTimeLocal(
|
||||
is_client=True, timezone=found_user.local_timezone
|
||||
)
|
||||
if not found_user:
|
||||
# UserLogger.log_login_attempt(
|
||||
# request, found_user.id, data.domain, data.access_key, success=True
|
||||
# request,
|
||||
# None,
|
||||
# data.domain,
|
||||
# data.access_key,
|
||||
# success=False,
|
||||
# error="Invalid credentials",
|
||||
# )
|
||||
response_data = {
|
||||
return ResponseHandler.unauthorized("Invalid credentials")
|
||||
return ResponseHandler.success(
|
||||
message="User logged in successfully",
|
||||
data={
|
||||
"access_token": access_dict.get("access_token"),
|
||||
"refresh_token": access_dict.get("refresher_token"),
|
||||
"access_object": access_dict.get("access_object"),
|
||||
"user": found_user.get_dict(),
|
||||
}
|
||||
return ResponseHandler.success(
|
||||
message="User logged in successfully",
|
||||
data=response_data,
|
||||
)
|
||||
except Exception as e:
|
||||
# UserLogger.log_login_attempt(
|
||||
# request, None, data.domain, data.access_key, success=False, error=str(e)
|
||||
# )
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=str(e))
|
||||
},
|
||||
)
|
||||
# except Exception as e:
|
||||
# # UserLogger.log_login_attempt(
|
||||
# # request, None, data.domain, data.access_key, success=False, error=str(e)
|
||||
# # )
|
||||
# raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=str(e))
|
||||
|
||||
|
||||
class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
@@ -125,6 +128,9 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
cls, data: EmployeeSelection, token_dict: EmployeeTokenObject, request: Request
|
||||
):
|
||||
"""Handle employee company selection"""
|
||||
Users.client_arrow = DateTimeLocal(
|
||||
is_client=True, timezone=token_dict.local_timezone
|
||||
)
|
||||
if data.company_uu_id not in token_dict.companies_uu_id_list:
|
||||
return ResponseHandler.unauthorized(
|
||||
"Company not found in user's company list"
|
||||
|
||||
Reference in New Issue
Block a user