redis implemntations and api setup completed
This commit is contained in:
@@ -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)))
|
||||
|
||||
Reference in New Issue
Block a user