language models and set defaults are updated
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.Schemas import Users
|
||||
|
||||
from .models import AuthenticationRequestModels, AuthenticationResponseModels
|
||||
from .function_handlers import AuthenticationFunctions
|
||||
|
||||
from ApiLayers.LanguageModels.Request import LoginRequestLanguageModel
|
||||
|
||||
# Auth Login
|
||||
authentication_login_super_user_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=AuthenticationRequestModels.LoginSuperUserRequestModel,
|
||||
# response_validator=LoginSuperUserResponseModel,
|
||||
language_models=[],
|
||||
response_validator=AuthenticationResponseModels.LoginSuperUserResponseModel,
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
@@ -24,7 +26,8 @@ authentication_select_super_user_event = Event(
|
||||
name="authentication_select_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=AuthenticationRequestModels.SelectCompanyOrOccupantTypeSuperUserRequestModel,
|
||||
# response_validator=SelectCompanyOrOccupantTypeSuperUserResponseModel,
|
||||
language_models=[],
|
||||
response_validator=AuthenticationResponseModels.SelectCompanyOrOccupantTypeSuperUserResponseModel,
|
||||
description="Select company or occupant type super user",
|
||||
)
|
||||
|
||||
@@ -39,6 +42,7 @@ authentication_check_token_event = Event(
|
||||
name="authentication_check_token_event",
|
||||
key="b6e3d1e2-4f9c-5c1g-9d8e-7e5f6f5e5d5f",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Check if token is valid",
|
||||
)
|
||||
@@ -54,6 +58,7 @@ authentication_refresh_user_info_event = Event(
|
||||
name="authentication_refresh_user_info_event",
|
||||
key="c7f4e2f3-5g0d-6d2h-0e9f-8f6g7g6f6e6g",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Refresh user information",
|
||||
)
|
||||
@@ -69,6 +74,7 @@ authentication_change_password_event = Event(
|
||||
name="authentication_change_password_event",
|
||||
key="d8g5f3g4-6h1e-7e3i-1f0g-9g7h8h7g7f7h",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Change user password",
|
||||
)
|
||||
@@ -84,6 +90,7 @@ authentication_create_password_event = Event(
|
||||
name="authentication_create_password_event",
|
||||
key="e9h6g4h5-7i2f-8f4j-2g1h-0h8i9i8h8g8i",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Create new password",
|
||||
)
|
||||
@@ -99,6 +106,7 @@ authentication_disconnect_user_event = Event(
|
||||
name="authentication_disconnect_user_event",
|
||||
key="f0i7h5i6-8j3g-9g5k-3h2i-1i9j0j9i9h9j",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Disconnect all user sessions",
|
||||
)
|
||||
@@ -114,6 +122,7 @@ authentication_logout_user_event = Event(
|
||||
name="authentication_logout_user_event",
|
||||
key="g1j8i6j7-9k4h-0h6l-4i3j-2j0k1k0j0i0k",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Logout user session",
|
||||
)
|
||||
@@ -129,6 +138,7 @@ authentication_refresher_token_event = Event(
|
||||
name="authentication_refresher_token_event",
|
||||
key="h2k9j7k8-0l5i-1i7m-5j4k-3k1l2l1k1j1l",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Refresh authentication token",
|
||||
)
|
||||
@@ -144,6 +154,7 @@ authentication_forgot_password_event = Event(
|
||||
name="authentication_forgot_password_event",
|
||||
key="i3l0k8l9-1m6j-2j8n-6k5l-4l2m3m2l2k2m",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Request password reset",
|
||||
)
|
||||
@@ -159,6 +170,7 @@ authentication_reset_password_event = Event(
|
||||
name="authentication_reset_password_event",
|
||||
key="j4m1l9m0-2n7k-3k9o-7l6m-5m3n4n3m3l3n",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Reset user password",
|
||||
)
|
||||
@@ -174,6 +186,7 @@ authentication_download_avatar_event = Event(
|
||||
name="authentication_download_avatar_event",
|
||||
key="k5n2m0n1-3o8l-4l0p-8m7n-6n4o5o4n4m4o",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[Users.__language_model__],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Download user avatar and profile info",
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Authentication related API endpoints.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict
|
||||
from fastapi import Request
|
||||
|
||||
@@ -40,7 +41,7 @@ AuthenticationLoginEventMethods = MethodToEvent(
|
||||
|
||||
|
||||
def authentication_login_with_domain_and_creds_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
event_2_catch = AuthenticationLoginEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_login_super_user_event.key}"
|
||||
@@ -70,21 +71,27 @@ AuthenticationSelectEventMethods = MethodToEvent(
|
||||
|
||||
|
||||
def authentication_select_company_or_occupant_type(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Select company or occupant type.
|
||||
"""
|
||||
context_retriever = ContextRetrievers(func=authentication_select_company_or_occupant_type)
|
||||
context_retriever = ContextRetrievers(
|
||||
func=authentication_select_company_or_occupant_type
|
||||
)
|
||||
function = AuthenticationSelectEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_select_super_user_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
data_model = None
|
||||
if context_retriever.token.is_employee:
|
||||
data_model = function.REQUEST_VALIDATOR.get('EmployeeSelection', None)(**data.data)
|
||||
data_model = function.REQUEST_VALIDATOR.get("EmployeeSelection", None)(
|
||||
**data.data
|
||||
)
|
||||
elif context_retriever.token.is_occupant:
|
||||
data_model = function.REQUEST_VALIDATOR.get('OccupantSelection', None)(**data.data)
|
||||
data_model = function.REQUEST_VALIDATOR.get("OccupantSelection", None)(
|
||||
**data.data
|
||||
)
|
||||
return function.endpoint_callable(data=data_model)
|
||||
|
||||
|
||||
@@ -163,7 +170,9 @@ AuthenticationChangePasswordEventMethods = MethodToEvent(
|
||||
|
||||
|
||||
def authentication_change_password_event_callable(data: EndpointBaseRequestModel):
|
||||
context_retriever = ContextRetrievers(func=authentication_change_password_event_callable)
|
||||
context_retriever = ContextRetrievers(
|
||||
func=authentication_change_password_event_callable
|
||||
)
|
||||
function = AuthenticationChangePasswordEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_change_password_event.key}"
|
||||
)
|
||||
@@ -177,7 +186,7 @@ AuthenticationChangePasswordEventMethods.endpoint_callable = (
|
||||
|
||||
AuthenticationCreatePasswordEventMethods = MethodToEvent(
|
||||
name="AuthenticationCreatePasswordEventMethods",
|
||||
events={authentication_create_password_event: authentication_create_password_event},
|
||||
events={authentication_create_password_event.key: authentication_create_password_event},
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/create-password",
|
||||
|
||||
@@ -28,8 +28,10 @@ from Events.base_request_model import ContextRetrievers, TokenDictType
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_employee_selection(cls, request: Request, data: Any, token_dict: TokenDictType):
|
||||
@classmethod # Requires no auth context
|
||||
def handle_employee_selection(
|
||||
cls, request: Request, data: Any, token_dict: TokenDictType
|
||||
):
|
||||
db = Users.new_session()
|
||||
if data.company_uu_id not in token_dict.companies_uu_id_list:
|
||||
raise HTTPExceptionApi(
|
||||
@@ -66,7 +68,8 @@ class Handlers:
|
||||
# Get employee
|
||||
employee: Employees = Employees.filter_one(
|
||||
Employees.people_id == token_dict.person_id,
|
||||
Employees.staff_id.in_(staff_ids), db=db
|
||||
Employees.staff_id.in_(staff_ids),
|
||||
db=db,
|
||||
).data
|
||||
|
||||
if not employee:
|
||||
@@ -123,8 +126,10 @@ class Handlers:
|
||||
sys_msg=f"{e}",
|
||||
)
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_occupant_selection(cls, request: Request, data: Any, token_dict: TokenDictType):
|
||||
@classmethod # Requires no auth context
|
||||
def handle_occupant_selection(
|
||||
cls, request: Request, data: Any, token_dict: TokenDictType
|
||||
):
|
||||
"""Handle occupant type selection"""
|
||||
db = BuildLivingSpace.new_session()
|
||||
# Get selected occupant type
|
||||
@@ -207,7 +212,7 @@ class AuthenticationFunctions:
|
||||
|
||||
context_retriever: Union[ContextRetrievers] = None
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
@classmethod # Requires no auth context
|
||||
def authentication_login_with_domain_and_creds(cls, request: Request, data: Any):
|
||||
"""
|
||||
Authenticate user with domain and credentials.
|
||||
@@ -215,12 +220,10 @@ class AuthenticationFunctions:
|
||||
Args:
|
||||
request: FastAPI request object
|
||||
data: Request body containing login credentials
|
||||
{
|
||||
"domain": "evyos.com.tr",
|
||||
"access_key": "karatay.berkay.sup@evyos.com.tr",
|
||||
"password": "string",
|
||||
"remember_me": false
|
||||
}
|
||||
{
|
||||
"domain": "evyos.com.tr", "access_key": "karatay.berkay.sup@evyos.com.tr",
|
||||
"password": "string", "remember_me": false
|
||||
}
|
||||
Returns:
|
||||
SuccessResponse containing authentication token and user info
|
||||
"""
|
||||
@@ -235,7 +238,7 @@ class AuthenticationFunctions:
|
||||
code="LOGIN_SUCCESS", lang=user_login_module.language
|
||||
).as_dict(data=user_login_module.as_dict)
|
||||
|
||||
@classmethod # Requires auth context
|
||||
@classmethod # Requires auth context
|
||||
def authentication_select_company_or_occupant_type(cls, data: Any):
|
||||
"""
|
||||
Handle selection of company or occupant type
|
||||
@@ -243,25 +246,31 @@ class AuthenticationFunctions:
|
||||
"""
|
||||
if cls.context_retriever.token.is_employee:
|
||||
if Handlers.handle_employee_selection(
|
||||
request=cls.context_retriever.request, data=data, token_dict=cls.context_retriever.token
|
||||
request=cls.context_retriever.request,
|
||||
data=data,
|
||||
token_dict=cls.context_retriever.token,
|
||||
):
|
||||
return EndpointSuccessResponse(
|
||||
code="LOGIN_SELECT", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={
|
||||
"selected": data.company_uu_id, **cls.context_retriever.base
|
||||
})
|
||||
).as_dict(
|
||||
data={"selected": data.company_uu_id, **cls.context_retriever.base}
|
||||
)
|
||||
elif cls.context_retriever.token.is_occupant:
|
||||
if Handlers.handle_occupant_selection(
|
||||
request=cls.context_retriever.request, data=data, token_dict=cls.context_retriever.token
|
||||
request=cls.context_retriever.request,
|
||||
data=data,
|
||||
token_dict=cls.context_retriever.token,
|
||||
):
|
||||
return EndpointSuccessResponse(
|
||||
code="LOGIN_SELECT", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={
|
||||
"selected": data.build_living_space_uu_id, **cls.context_retriever.base
|
||||
})
|
||||
return {"completed": False, "selected": None, **cls.context_retriever.base}
|
||||
).as_dict(
|
||||
data={
|
||||
"selected": data.build_living_space_uu_id,
|
||||
**cls.context_retriever.base,
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_check_token_is_valid(cls, data: Any):
|
||||
"""Check if token is valid for user"""
|
||||
# try:
|
||||
@@ -271,7 +280,7 @@ class AuthenticationFunctions:
|
||||
# return ResponseHandler.unauthorized("Access Token is NOT valid")
|
||||
return
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_refresh_user_info(cls, data: Any):
|
||||
"""Refresh user info using access token"""
|
||||
# try:
|
||||
@@ -300,7 +309,7 @@ class AuthenticationFunctions:
|
||||
# return ResponseHandler.error(str(e))
|
||||
return
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
@classmethod # Requires no auth context
|
||||
def authentication_change_password(cls, data: Any):
|
||||
"""Change password with access token"""
|
||||
# try:
|
||||
@@ -320,7 +329,7 @@ class AuthenticationFunctions:
|
||||
# return ResponseHandler.error(str(e))
|
||||
return
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_create_password(cls, data: Any):
|
||||
"""Create password with password reset token requested via email"""
|
||||
# if not data.re_password == data.password:
|
||||
@@ -333,7 +342,7 @@ class AuthenticationFunctions:
|
||||
# return ResponseHandler.not_found("Record not found")
|
||||
return
|
||||
|
||||
@classmethod # Requires auth context
|
||||
@classmethod # Requires auth context
|
||||
def authentication_disconnect_user(cls, data: Any):
|
||||
"""Disconnect all sessions of user in access token"""
|
||||
# found_user = Users.filter_one(Users.uu_id == token_dict.user_uu_id).data
|
||||
@@ -348,7 +357,7 @@ class AuthenticationFunctions:
|
||||
# return ResponseHandler.not_found("Invalid data")
|
||||
return
|
||||
|
||||
@classmethod # Requires auth context
|
||||
@classmethod # Requires auth context
|
||||
def authentication_logout_user(cls, data: Any):
|
||||
"""Logout only single session of user which domain is provided"""
|
||||
# token_user = None
|
||||
@@ -364,7 +373,7 @@ class AuthenticationFunctions:
|
||||
context_retriever = ContextRetrievers(func=cls.authentication_logout_user)
|
||||
return context_retriever.base
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_refresher_token(cls, data: Any):
|
||||
"""Refresh access token with refresher token"""
|
||||
# token_refresher = UsersTokens.filter_by_one(
|
||||
@@ -391,7 +400,7 @@ class AuthenticationFunctions:
|
||||
context_retriever = ContextRetrievers(func=cls.authentication_refresher_token)
|
||||
return context_retriever.base
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_forgot_password(cls, 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)
|
||||
@@ -410,7 +419,7 @@ class AuthenticationFunctions:
|
||||
# return ResponseHandler.success("Password is change link is sent to your email or phone", data={})
|
||||
return
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_reset_password(cls, data: Any):
|
||||
"""Reset password with forgot password token"""
|
||||
# from sqlalchemy import or_
|
||||
@@ -439,7 +448,7 @@ class AuthenticationFunctions:
|
||||
# return ResponseHandler.success("Password change link is sent to your email or phone", data=found_user.get_dict())
|
||||
return
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_download_avatar(cls, data: Any):
|
||||
"""Download avatar icon and profile info of user"""
|
||||
# if found_user := Users.filter_one(Users.id == token_dict.user_id).data:
|
||||
|
||||
@@ -6,10 +6,6 @@ from ApiLayers.ApiValidations.Request import (
|
||||
)
|
||||
|
||||
|
||||
class LoginSuperUserRequestModel(Login):
|
||||
pass
|
||||
|
||||
|
||||
class LoginSuperUserResponseModel(BaseModel):
|
||||
pass
|
||||
|
||||
@@ -37,14 +33,12 @@ class OccupantSelectionSuperUserRequestModel(BaseModel):
|
||||
class OccupantSelectionSuperUserResponseModel(BaseModel):
|
||||
pass
|
||||
|
||||
"""
|
||||
EmployeeSelection,
|
||||
OccupantSelection,
|
||||
"""
|
||||
|
||||
class AuthenticationRequestModels:
|
||||
LoginSuperUserRequestModel = LoginSuperUserRequestModel
|
||||
LoginSuperUserRequestModel = Login
|
||||
SelectCompanyOrOccupantTypeSuperUserRequestModel = {
|
||||
"EmployeeSelection": EmployeeSelection, "OccupantSelection":OccupantSelection
|
||||
"EmployeeSelection": EmployeeSelection,
|
||||
"OccupantSelection": OccupantSelection,
|
||||
}
|
||||
EmployeeSelectionSuperUserRequestModel = EmployeeSelectionSuperUserRequestModel
|
||||
OccupantSelectionSuperUserRequestModel = OccupantSelectionSuperUserRequestModel
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
"""
|
||||
Validations package initialization.
|
||||
"""
|
||||
|
||||
__all__ = []
|
||||
|
||||
Reference in New Issue
Block a user