language models and set defaults are updated

This commit is contained in:
2025-01-28 17:11:59 +03:00
parent c0bd9c1685
commit 5d3f946642
34 changed files with 638 additions and 126 deletions

View File

@@ -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: