redis implemntations and api setup completed
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from uuid import UUID
|
||||
from Events.Engine.abstract_class import Event
|
||||
|
||||
from .models import (
|
||||
@@ -14,8 +13,6 @@ from .models import (
|
||||
from .function_handlers import (
|
||||
authentication_login_with_domain_and_creds,
|
||||
authentication_select_company_or_occupant_type,
|
||||
handle_employee_selection,
|
||||
handle_occupant_selection,
|
||||
authentication_check_token_is_valid,
|
||||
authentication_refresh_user_info,
|
||||
authentication_change_password,
|
||||
@@ -31,124 +28,126 @@ from .function_handlers import (
|
||||
|
||||
# Auth Login
|
||||
authentication_login_super_user_event = Event(
|
||||
key=UUID("a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e"),
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=LoginSuperUserRequestModel,
|
||||
response_validator=LoginSuperUserResponseModel,
|
||||
# response_validator=LoginSuperUserResponseModel,
|
||||
description="Login super user",
|
||||
)
|
||||
authentication_login_super_user_event.endpoint_callable = authentication_login_with_domain_and_creds
|
||||
authentication_login_super_user_event.endpoint_callable = (
|
||||
authentication_login_with_domain_and_creds
|
||||
)
|
||||
|
||||
# Auth Select Company or Occupant Type
|
||||
authentication_select_company_or_occupant_type_super_user_event = Event(
|
||||
key=UUID("a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e"),
|
||||
name="authentication_select_company_or_occupant_type_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=SelectCompanyOrOccupantTypeSuperUserRequestModel,
|
||||
response_validator=SelectCompanyOrOccupantTypeSuperUserResponseModel,
|
||||
# response_validator=SelectCompanyOrOccupantTypeSuperUserResponseModel,
|
||||
description="Select company or occupant type super user",
|
||||
)
|
||||
authentication_select_company_or_occupant_type_super_user_event.endpoint_callable = authentication_select_company_or_occupant_type
|
||||
|
||||
authentication_employee_selection_super_user_event = Event(
|
||||
key=UUID("a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e"),
|
||||
request_validator=EmployeeSelectionSuperUserRequestModel,
|
||||
response_validator=EmployeeSelectionSuperUserResponseModel,
|
||||
description="Employee selection super user",
|
||||
authentication_select_company_or_occupant_type_super_user_event.endpoint_callable = (
|
||||
authentication_select_company_or_occupant_type
|
||||
)
|
||||
authentication_employee_selection_super_user_event.endpoint_callable = handle_employee_selection
|
||||
|
||||
authentication_occupant_selection_super_user_event = Event(
|
||||
key=UUID("a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e"),
|
||||
request_validator=OccupantSelectionSuperUserRequestModel,
|
||||
response_validator=OccupantSelectionSuperUserResponseModel,
|
||||
description="Occupant selection super user",
|
||||
)
|
||||
authentication_occupant_selection_super_user_event.endpoint_callable = handle_occupant_selection
|
||||
|
||||
# Check Token Validity
|
||||
authentication_check_token_event = Event(
|
||||
key=UUID("b6e3d1e2-4f9c-5c1g-9d8e-7e5f6f5e5d5f"),
|
||||
name="authentication_check_token_event",
|
||||
key="b6e3d1e2-4f9c-5c1g-9d8e-7e5f6f5e5d5f",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Check if token is valid",
|
||||
)
|
||||
authentication_check_token_event.endpoint_callable = authentication_check_token_is_valid
|
||||
|
||||
# Refresh User Info
|
||||
authentication_refresh_user_info_event = Event(
|
||||
key=UUID("c7f4e2f3-5g0d-6d2h-0e9f-8f6g7g6f6e6g"),
|
||||
name="authentication_refresh_user_info_event",
|
||||
key="c7f4e2f3-5g0d-6d2h-0e9f-8f6g7g6f6e6g",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Refresh user information",
|
||||
)
|
||||
authentication_refresh_user_info_event.endpoint_callable = authentication_refresh_user_info
|
||||
authentication_refresh_user_info_event.endpoint_callable = (
|
||||
authentication_refresh_user_info
|
||||
)
|
||||
|
||||
# Change Password
|
||||
authentication_change_password_event = Event(
|
||||
key=UUID("d8g5f3g4-6h1e-7e3i-1f0g-9g7h8h7g7f7h"),
|
||||
name="authentication_change_password_event",
|
||||
key="d8g5f3g4-6h1e-7e3i-1f0g-9g7h8h7g7f7h",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Change user password",
|
||||
)
|
||||
authentication_change_password_event.endpoint_callable = authentication_change_password
|
||||
|
||||
# Create Password
|
||||
authentication_create_password_event = Event(
|
||||
key=UUID("e9h6g4h5-7i2f-8f4j-2g1h-0h8i9i8h8g8i"),
|
||||
name="authentication_create_password_event",
|
||||
key="e9h6g4h5-7i2f-8f4j-2g1h-0h8i9i8h8g8i",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Create new password",
|
||||
)
|
||||
authentication_create_password_event.endpoint_callable = authentication_create_password
|
||||
|
||||
# Disconnect User
|
||||
authentication_disconnect_user_event = Event(
|
||||
key=UUID("f0i7h5i6-8j3g-9g5k-3h2i-1i9j0j9i9h9j"),
|
||||
name="authentication_disconnect_user_event",
|
||||
key="f0i7h5i6-8j3g-9g5k-3h2i-1i9j0j9i9h9j",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Disconnect all user sessions",
|
||||
)
|
||||
authentication_disconnect_user_event.endpoint_callable = authentication_disconnect_user
|
||||
|
||||
# Logout User
|
||||
authentication_logout_user_event = Event(
|
||||
key=UUID("g1j8i6j7-9k4h-0h6l-4i3j-2j0k1k0j0i0k"),
|
||||
name="authentication_logout_user_event",
|
||||
key="g1j8i6j7-9k4h-0h6l-4i3j-2j0k1k0j0i0k",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Logout user session",
|
||||
)
|
||||
authentication_logout_user_event.endpoint_callable = authentication_logout_user
|
||||
|
||||
# Refresh Token
|
||||
authentication_refresher_token_event = Event(
|
||||
key=UUID("h2k9j7k8-0l5i-1i7m-5j4k-3k1l2l1k1j1l"),
|
||||
name="authentication_refresher_token_event",
|
||||
key="h2k9j7k8-0l5i-1i7m-5j4k-3k1l2l1k1j1l",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Refresh authentication token",
|
||||
)
|
||||
authentication_refresher_token_event.endpoint_callable = authentication_refresher_token
|
||||
|
||||
# Forgot Password
|
||||
authentication_forgot_password_event = Event(
|
||||
key=UUID("i3l0k8l9-1m6j-2j8n-6k5l-4l2m3m2l2k2m"),
|
||||
name="authentication_forgot_password_event",
|
||||
key="i3l0k8l9-1m6j-2j8n-6k5l-4l2m3m2l2k2m",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Request password reset",
|
||||
)
|
||||
authentication_forgot_password_event.endpoint_callable = authentication_forgot_password
|
||||
|
||||
# Reset Password
|
||||
authentication_reset_password_event = Event(
|
||||
key=UUID("j4m1l9m0-2n7k-3k9o-7l6m-5m3n4n3m3l3n"),
|
||||
name="authentication_reset_password_event",
|
||||
key="j4m1l9m0-2n7k-3k9o-7l6m-5m3n4n3m3l3n",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Reset user password",
|
||||
)
|
||||
authentication_reset_password_event.endpoint_callable = authentication_reset_password
|
||||
|
||||
# Download Avatar
|
||||
authentication_download_avatar_event = Event(
|
||||
key=UUID("k5n2m0n1-3o8l-4l0p-8m7n-6n4o5o4n4m4o"),
|
||||
name="authentication_download_avatar_event",
|
||||
key="k5n2m0n1-3o8l-4l0p-8m7n-6n4o5o4n4m4o",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Download user avatar and profile info",
|
||||
)
|
||||
authentication_download_avatar_event.endpoint_callable = authentication_download_avatar
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
Authentication related API endpoints.
|
||||
"""
|
||||
|
||||
from typing import Union
|
||||
from typing import Union, Any, Dict
|
||||
|
||||
from ApiLayers.Middleware import MiddlewareModule, TokenEventMiddleware
|
||||
from ApiLayers.ApiValidations.Request import EmployeeSelection, OccupantSelection
|
||||
|
||||
from Events.Engine.abstract_class import MethodToEvent
|
||||
from Events.base_request_model import SuccessResponse
|
||||
|
||||
from ApiLayers.ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from ApiLayers.ApiServices.Token.token_handler import OccupantTokenObject, EmployeeTokenObject
|
||||
from Events.base_request_model import EndpointBaseRequestModel
|
||||
|
||||
from .api_events import (
|
||||
authentication_login_super_user_event,
|
||||
authentication_select_company_or_occupant_type_super_user_event,
|
||||
authentication_employee_selection_super_user_event,
|
||||
authentication_occupant_selection_super_user_event,
|
||||
authentication_check_token_event,
|
||||
authentication_refresh_user_info_event,
|
||||
authentication_change_password_event,
|
||||
@@ -27,13 +25,18 @@ from .api_events import (
|
||||
authentication_download_avatar_event,
|
||||
)
|
||||
|
||||
from fastapi import Request
|
||||
|
||||
|
||||
# Type aliases for common types
|
||||
TokenDictType = Union["EmployeeTokenObject", "OccupantTokenObject"]
|
||||
|
||||
|
||||
AuthenticationLoginEventMethods = MethodToEvent(
|
||||
events=[authentication_login_super_user_event],
|
||||
name="AuthenticationLoginEventMethods",
|
||||
events={
|
||||
authentication_login_super_user_event.key: authentication_login_super_user_event,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/authentication/login",
|
||||
@@ -42,13 +45,24 @@ AuthenticationLoginEventMethods = MethodToEvent(
|
||||
description="Login to the system via domain, access key : [email] | [phone]",
|
||||
)
|
||||
|
||||
def authentication_login_with_domain_and_creds(
|
||||
request: Request,
|
||||
data: EndpointBaseRequestModel,
|
||||
) -> Dict[str, Any]:
|
||||
function = AuthenticationLoginEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_login_super_user_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(request=request, data=data)
|
||||
|
||||
|
||||
AuthenticationLoginEventMethods.endpoint_callable = authentication_login_with_domain_and_creds
|
||||
|
||||
AuthenticationSelectEventMethods = MethodToEvent(
|
||||
events=[
|
||||
authentication_select_company_or_occupant_type_super_user_event,
|
||||
authentication_employee_selection_super_user_event,
|
||||
authentication_occupant_selection_super_user_event
|
||||
],
|
||||
name="AuthenticationSelectEventMethods",
|
||||
events={
|
||||
authentication_select_company_or_occupant_type_super_user_event.key: authentication_select_company_or_occupant_type_super_user_event,
|
||||
},
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/authentication/select",
|
||||
@@ -57,22 +71,53 @@ AuthenticationSelectEventMethods = MethodToEvent(
|
||||
description="Select company or occupant type",
|
||||
)
|
||||
|
||||
def authentication_select_company_or_occupant_type(
|
||||
request: Request,
|
||||
data: EndpointBaseRequestModel,
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Select company or occupant type.
|
||||
"""
|
||||
auth_dict = authentication_select_company_or_occupant_type.auth
|
||||
function = AuthenticationSelectEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_select_company_or_occupant_type_super_user_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(request=request, data=data, token_dict=auth_dict)
|
||||
|
||||
|
||||
AuthenticationSelectEventMethods.endpoint_callable = authentication_select_company_or_occupant_type
|
||||
|
||||
AuthenticationCheckTokenEventMethods = MethodToEvent(
|
||||
events=[authentication_check_token_event],
|
||||
name="AuthenticationCheckTokenEventMethods",
|
||||
events={
|
||||
authentication_check_token_event.key: authentication_check_token_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/authentication/check-token",
|
||||
method="POST",
|
||||
summary="Check if token is valid",
|
||||
description="Check if access token is valid for user",
|
||||
)
|
||||
|
||||
def authentication_check_token_is_valid(request: Request):
|
||||
function = AuthenticationCheckTokenEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_check_token_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(request=request)
|
||||
|
||||
|
||||
AuthenticationCheckTokenEventMethods.endpoint_callable = authentication_check_token_is_valid
|
||||
|
||||
AuthenticationRefreshEventMethods = MethodToEvent(
|
||||
events=[authentication_refresh_user_info_event],
|
||||
name="AuthenticationRefreshEventMethods",
|
||||
events={
|
||||
authentication_refresh_user_info_event.key: authentication_refresh_user_info_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/authentication/refresh",
|
||||
method="POST",
|
||||
summary="Refresh user info",
|
||||
@@ -80,19 +125,45 @@ AuthenticationRefreshEventMethods = MethodToEvent(
|
||||
)
|
||||
|
||||
|
||||
def authentication_refresh_user_info(request: Request):
|
||||
token_dict = authentication_refresh_user_info.auth
|
||||
function = AuthenticationRefreshEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_refresh_user_info_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(request=request, token_dict=token_dict)
|
||||
|
||||
|
||||
AuthenticationRefreshEventMethods.endpoint_callable = authentication_refresh_user_info
|
||||
|
||||
AuthenticationChangePasswordEventMethods = MethodToEvent(
|
||||
events=[authentication_change_password_event],
|
||||
name="AuthenticationChangePasswordEventMethods",
|
||||
events={
|
||||
authentication_change_password_event.key: authentication_change_password_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/authentication/change-password",
|
||||
method="POST",
|
||||
summary="Change password",
|
||||
description="Change password with access token",
|
||||
)
|
||||
|
||||
def authentication_change_password_event_callable(request: Request, data: EndpointBaseRequestModel):
|
||||
token_dict = authentication_change_password_event_callable.auth
|
||||
function = AuthenticationChangePasswordEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_change_password_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(data=data, token_dict=token_dict)
|
||||
|
||||
|
||||
AuthenticationChangePasswordEventMethods.endpoint_callable = authentication_change_password_event_callable
|
||||
|
||||
AuthenticationCreatePasswordEventMethods = MethodToEvent(
|
||||
events=[authentication_create_password_event],
|
||||
name="AuthenticationCreatePasswordEventMethods",
|
||||
events={
|
||||
authentication_create_password_event: authentication_create_password_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/authentication/create-password",
|
||||
@@ -101,9 +172,21 @@ AuthenticationCreatePasswordEventMethods = MethodToEvent(
|
||||
description="Create password with password reset token requested via email",
|
||||
)
|
||||
|
||||
def authentication_create_password(data: EndpointBaseRequestModel):
|
||||
function = AuthenticationCreatePasswordEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_create_password_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(data=data)
|
||||
|
||||
|
||||
AuthenticationCreatePasswordEventMethods.endpoint_callable = authentication_create_password
|
||||
|
||||
AuthenticationDisconnectUserEventMethods = MethodToEvent(
|
||||
events=[authentication_disconnect_user_event],
|
||||
name="AuthenticationDisconnectUserEventMethods",
|
||||
events={
|
||||
authentication_disconnect_user_event.key: authentication_disconnect_user_event
|
||||
},
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/authentication/disconnect",
|
||||
@@ -112,9 +195,19 @@ AuthenticationDisconnectUserEventMethods = MethodToEvent(
|
||||
description="Disconnect all sessions of user in access token",
|
||||
)
|
||||
|
||||
def authentication_disconnect_user(request: Request, data: EndpointBaseRequestModel):
|
||||
token_dict = authentication_disconnect_user.auth
|
||||
function = AuthenticationDisconnectUserEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_disconnect_user_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(data=data, token_dict=token_dict)
|
||||
|
||||
|
||||
AuthenticationLogoutEventMethods = MethodToEvent(
|
||||
events=[authentication_logout_user_event],
|
||||
name="AuthenticationLogoutEventMethods",
|
||||
events={
|
||||
authentication_logout_user_event.key: authentication_logout_user_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/authentication/logout",
|
||||
@@ -123,20 +216,51 @@ AuthenticationLogoutEventMethods = MethodToEvent(
|
||||
description="Logout only single session of user which domain is provided",
|
||||
)
|
||||
|
||||
@TokenEventMiddleware.event_required
|
||||
def authentication_logout_user(request: Request, data: EndpointBaseRequestModel):
|
||||
function = AuthenticationLogoutEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_logout_user_event.key}"
|
||||
)
|
||||
print('authentication_logout_user', dict(
|
||||
auth=getattr(authentication_logout_user, "auth", None),
|
||||
func_code=getattr(authentication_logout_user, "func_code", None),
|
||||
))
|
||||
function.endpoint_callable.auth = getattr(authentication_logout_user, "auth", None)
|
||||
function.endpoint_callable.func_code = getattr(authentication_logout_user, "func_code", None)
|
||||
return function.endpoint_callable(request=request, data=data)
|
||||
|
||||
|
||||
AuthenticationLogoutEventMethods.endpoint_callable = authentication_logout_user
|
||||
|
||||
AuthenticationRefreshTokenEventMethods = MethodToEvent(
|
||||
events=[authentication_refresher_token_event],
|
||||
name="AuthenticationRefreshTokenEventMethods",
|
||||
events={
|
||||
authentication_refresher_token_event.key: authentication_refresher_token_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required, ],
|
||||
url="/authentication/refresh-token",
|
||||
method="POST",
|
||||
summary="Refresh token",
|
||||
description="Refresh access token with refresher token",
|
||||
)
|
||||
|
||||
def authentication_refresher_token(request: Request, data: EndpointBaseRequestModel):
|
||||
token_dict = authentication_refresher_token.auth
|
||||
function = AuthenticationRefreshTokenEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_refresher_token_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(data=data, request=request, token_dict=token_dict)
|
||||
|
||||
AuthenticationRefreshTokenEventMethods.endpoint_callable = authentication_refresher_token
|
||||
|
||||
|
||||
AuthenticationForgotPasswordEventMethods = MethodToEvent(
|
||||
events=[authentication_forgot_password_event],
|
||||
name="AuthenticationForgotPasswordEventMethods",
|
||||
events={
|
||||
authentication_forgot_password_event.key: authentication_forgot_password_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/authentication/forgot-password",
|
||||
@@ -146,10 +270,25 @@ AuthenticationForgotPasswordEventMethods = MethodToEvent(
|
||||
)
|
||||
|
||||
|
||||
def authentication_forgot_password(request: Request, data: EndpointBaseRequestModel):
|
||||
token_dict = authentication_forgot_password.auth
|
||||
function = AuthenticationForgotPasswordEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_forgot_password_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(data=data, token_dict=token_dict)
|
||||
|
||||
|
||||
AuthenticationForgotPasswordEventMethods.endpoint_callable = authentication_forgot_password
|
||||
|
||||
|
||||
AuthenticationResetPasswordEventMethods = MethodToEvent(
|
||||
events=[authentication_reset_password_event],
|
||||
name="AuthenticationResetPasswordEventMethods",
|
||||
events={
|
||||
authentication_reset_password_event.key: authentication_reset_password_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/authentication/reset-password",
|
||||
method="POST",
|
||||
summary="Reset password",
|
||||
@@ -157,12 +296,38 @@ AuthenticationResetPasswordEventMethods = MethodToEvent(
|
||||
)
|
||||
|
||||
|
||||
def authentication_reset_password(data: EndpointBaseRequestModel):
|
||||
# token_dict = authentication_reset_password.auth
|
||||
function = AuthenticationResetPasswordEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_reset_password_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(data=data)
|
||||
|
||||
|
||||
AuthenticationResetPasswordEventMethods.endpoint_callable = authentication_reset_password
|
||||
|
||||
AuthenticationDownloadAvatarEventMethods = MethodToEvent(
|
||||
events=[authentication_download_avatar_event],
|
||||
name="AuthenticationDownloadAvatarEventMethods",
|
||||
events={
|
||||
authentication_download_avatar_event.key: authentication_download_avatar_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[],
|
||||
url="/authentication/download-avatar",
|
||||
method="POST",
|
||||
summary="Download avatar",
|
||||
description="Download avatar icon and profile info of user",
|
||||
)
|
||||
|
||||
|
||||
@MiddlewareModule.auth_required
|
||||
def authentication_download_avatar(request: Request):
|
||||
token_dict = authentication_download_avatar.auth
|
||||
function = AuthenticationDownloadAvatarEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_download_avatar_event.key}"
|
||||
)
|
||||
return function.endpoint_callable(token_dict=token_dict)
|
||||
|
||||
|
||||
AuthenticationDownloadAvatarEventMethods.endpoint_callable = authentication_download_avatar
|
||||
|
||||
@@ -18,6 +18,7 @@ from .auth import (
|
||||
|
||||
|
||||
AuthCluster = CategoryCluster(
|
||||
name="AuthCluster",
|
||||
tags=["authentication"],
|
||||
prefix="/authentication",
|
||||
description="Authentication cluster",
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
from typing import Any, TYPE_CHECKING, Union
|
||||
|
||||
from Events.base_request_model import TokenDictType
|
||||
from Events.Engine.abstract_class import MethodToEvent
|
||||
from Events.base_request_model import SuccessResponse
|
||||
from typing import Any, TYPE_CHECKING, Union, Dict
|
||||
|
||||
from ApiLayers.ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from ApiLayers.ApiLibrary.date_time_actions.date_functions import DateTimeLocal
|
||||
from ApiLayers.ApiServices.middleware.auth_middleware import AuthMiddlewareModule
|
||||
|
||||
from ApiLayers.ApiServices.Login.user_login_handler import UserLoginModule
|
||||
from ApiLayers.ApiServices.Token.token_handler import TokenService
|
||||
@@ -17,20 +11,17 @@ from ApiLayers.Schemas import (
|
||||
BuildParts,
|
||||
RelationshipEmployee2Build,
|
||||
Companies,
|
||||
Departments,
|
||||
Duties,
|
||||
Departments,
|
||||
Duties,
|
||||
Duty,
|
||||
Staff,
|
||||
Employees,
|
||||
Event2Employee,
|
||||
Event2Occupant,
|
||||
OccupantTypes,
|
||||
Users
|
||||
Users,
|
||||
)
|
||||
from ApiLayers.ApiServices.Token.token_handler import OccupantTokenObject, EmployeeTokenObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from fastapi import Request
|
||||
from fastapi import Request
|
||||
|
||||
|
||||
# Type aliases for common types
|
||||
@@ -70,7 +61,7 @@ def authentication_login_with_domain_and_creds(request: Request, data: Any):
|
||||
"user": token.get("user"),
|
||||
}
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
|
||||
def handle_employee_selection(request: Request, data: Any, token_dict: TokenDictType):
|
||||
Users.set_user_define_properties(token=token_dict)
|
||||
db_session = Users.new_session()
|
||||
@@ -185,7 +176,6 @@ def handle_employee_selection(request: Request, data: Any, token_dict: TokenDict
|
||||
)
|
||||
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
def handle_occupant_selection(request: Request, data: Any, token_dict: TokenDictType):
|
||||
"""Handle occupant type selection"""
|
||||
db = BuildLivingSpace.new_session()
|
||||
@@ -270,17 +260,20 @@ def handle_occupant_selection(request: Request, data: Any, token_dict: TokenDict
|
||||
)
|
||||
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
def authentication_select_company_or_occupant_type(request: Request, data: Any, token_dict: TokenDictType):
|
||||
"""Handle selection of company or occupant type"""
|
||||
if token_dict.is_employee:
|
||||
return cls._handle_employee_selection(data, token_dict, request)
|
||||
if handle_employee_selection(data, token_dict, request):
|
||||
return {"selected_occupant": None, "selected_company": data.company_uu_id}
|
||||
elif token_dict.is_occupant:
|
||||
return cls._handle_occupant_selection(data, token_dict, request)
|
||||
if handle_occupant_selection(data, token_dict, request):
|
||||
return {
|
||||
"selected_company": None, "selected_occupant": data.build_living_space_uu_id,
|
||||
}
|
||||
return {"completed": False, "selected_company": None, "selected_occupant": None}
|
||||
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
def authentication_check_token_is_valid(request: "Request", data: Any):
|
||||
def authentication_check_token_is_valid(request: Request, data: Any):
|
||||
"""Check if token is valid for user"""
|
||||
# try:
|
||||
# if RedisActions.get_object_via_access_key(request=request):
|
||||
@@ -290,8 +283,7 @@ def authentication_check_token_is_valid(request: "Request", data: Any):
|
||||
return
|
||||
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
def authentication_refresh_user_info(request: "Request", token_dict: TokenDictType, data: Any):
|
||||
def authentication_refresh_user_info(request: Request, token_dict: TokenDictType, data: Any):
|
||||
"""Refresh user info using access token"""
|
||||
# try:
|
||||
# access_token = request.headers.get(Auth.ACCESS_TOKEN_TAG)
|
||||
@@ -320,8 +312,7 @@ def authentication_refresh_user_info(request: "Request", token_dict: TokenDictTy
|
||||
return
|
||||
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
def authentication_change_password(request: "Request", token_dict: TokenDictType, data: Any):
|
||||
def authentication_change_password(request: Request, token_dict: TokenDictType, data: Any):
|
||||
"""Change password with access token"""
|
||||
# try:
|
||||
# if not isinstance(token_dict, EmployeeTokenObject):
|
||||
@@ -341,7 +332,7 @@ def authentication_change_password(request: "Request", token_dict: TokenDictType
|
||||
return
|
||||
|
||||
|
||||
def authentication_create_password(request: "Request", data: Any):
|
||||
def authentication_create_password(request: Request, data: Any):
|
||||
"""Create password with password reset token requested via email"""
|
||||
# if not data.re_password == data.password:
|
||||
# raise HTTPException(status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match")
|
||||
@@ -354,8 +345,7 @@ def authentication_create_password(request: "Request", data: Any):
|
||||
return
|
||||
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
def authentication_disconnect_user(request: "Request", token_dict: TokenDictType, data: Any):
|
||||
def authentication_disconnect_user(request: Request, token_dict: TokenDictType, data: Any):
|
||||
"""Disconnect all sessions of user in access token"""
|
||||
# found_user = Users.filter_one(Users.uu_id == token_dict.user_uu_id).data
|
||||
# if not found_user:
|
||||
@@ -370,7 +360,7 @@ def authentication_disconnect_user(request: "Request", token_dict: TokenDictType
|
||||
return
|
||||
|
||||
|
||||
def authentication_logout_user(request: "Request", data: Any, token_dict: TokenDictType):
|
||||
def authentication_logout_user(request: Request, data: Any):
|
||||
"""Logout only single session of user which domain is provided"""
|
||||
# token_user = None
|
||||
# if already_tokens := RedisActions.get_object_via_access_key(request=request):
|
||||
@@ -382,11 +372,14 @@ def authentication_logout_user(request: "Request", data: Any, token_dict: TokenD
|
||||
# selected_user.remove_refresher_token(domain=data.domain)
|
||||
# return ResponseHandler.success("Session is logged out", data=token_user)
|
||||
# return ResponseHandler.not_found("Logout is not successfully completed")
|
||||
token_dict = authentication_logout_user.auth
|
||||
print('token_dict', token_dict)
|
||||
func_code = authentication_logout_user.func_code
|
||||
print('func_code', func_code)
|
||||
return
|
||||
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
def authentication_refresher_token(request: "Request", token_dict: TokenDictType, data: Any):
|
||||
def authentication_refresher_token(request: Request, token_dict: TokenDictType, data: Any):
|
||||
"""Refresh access token with refresher token"""
|
||||
# token_refresher = UsersTokens.filter_by_one(
|
||||
# token=data.refresh_token,
|
||||
@@ -412,7 +405,7 @@ def authentication_refresher_token(request: "Request", token_dict: TokenDictType
|
||||
return
|
||||
|
||||
|
||||
def authentication_forgot_password(request: "Request", data: Any):
|
||||
def authentication_forgot_password(request: Request, data: Any):
|
||||
"""Send an email to user for a valid password reset token"""
|
||||
# found_user: Users = Users.check_user_exits(access_key=data.access_key, domain=data.domain)
|
||||
# forgot_key = AuthActions.save_access_token_to_redis(request=request, found_user=found_user, domain=data.domain)
|
||||
@@ -431,8 +424,7 @@ def authentication_forgot_password(request: "Request", data: Any):
|
||||
return
|
||||
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
def authentication_reset_password(request: "Request", data: Any):
|
||||
def authentication_reset_password(request: Request, data: Any):
|
||||
"""Reset password with forgot password token"""
|
||||
# from sqlalchemy import or_
|
||||
# found_user = Users.query.filter(
|
||||
@@ -461,8 +453,7 @@ def authentication_reset_password(request: "Request", data: Any):
|
||||
return
|
||||
|
||||
|
||||
@AuthMiddlewareModule.auth_required
|
||||
def authentication_download_avatar(request: "Request", data: Any, token_dict: TokenDictType):
|
||||
def authentication_download_avatar(request: Request, data: Any, token_dict: TokenDictType):
|
||||
"""Download avatar icon and profile info of user"""
|
||||
# if found_user := Users.filter_one(Users.id == token_dict.user_id).data:
|
||||
# expired_starts = str(system_arrow.now() - system_arrow.get(str(found_user.expiry_ends)))
|
||||
|
||||
@@ -9,5 +9,3 @@ authentication_page_info = PageInfo(
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -31,4 +31,3 @@ class OccupantSelectionSuperUserRequestModel(BaseModel):
|
||||
|
||||
class OccupantSelectionSuperUserResponseModel(BaseModel):
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user