alchemy flush and save functions updated
This commit is contained in:
@@ -50,15 +50,18 @@ def save_access_token_to_redis(
|
||||
Employees,
|
||||
Staff,
|
||||
)
|
||||
print('save_access_token_to_redis')
|
||||
if not found_user:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=dict(message="User is not found."),
|
||||
headers=request.headers,
|
||||
# headers=json.loads(json.dumps(request.headers)),
|
||||
)
|
||||
|
||||
print('save_access_token_to_redis', found_user)
|
||||
# Check user is already logged in or has a previous session
|
||||
already_tokens = get_object_via_user_uu_id(user_id=found_user.uu_id)
|
||||
print('already_tokens', already_tokens)
|
||||
for key in already_tokens or []:
|
||||
token_user = json.loads(redis_cli.get(key).decode() or {})
|
||||
if token_user.get("domain", "") == domain:
|
||||
@@ -67,11 +70,11 @@ def save_access_token_to_redis(
|
||||
access_token = (
|
||||
found_user.generate_access_token() if not access_token else access_token
|
||||
)
|
||||
|
||||
print('access_token', access_token)
|
||||
# Prepare the user's details to save in Redis Session
|
||||
if found_user.is_occupant: # Check if user is NOT an occupant
|
||||
living_spaces: list[BuildLivingSpace] = BuildLivingSpace.filter_active(
|
||||
BuildLivingSpace.person_id == found_user.person_id, filter_records=False
|
||||
living_spaces: list[BuildLivingSpace] = BuildLivingSpace.filter_all(
|
||||
BuildLivingSpace.person_id == found_user.person_id
|
||||
).data
|
||||
if not living_spaces:
|
||||
raise HTTPException(
|
||||
@@ -79,9 +82,9 @@ def save_access_token_to_redis(
|
||||
detail=dict(
|
||||
message="NO Living Space is found. This user has no proper account set please contact the admin."
|
||||
),
|
||||
headers=request.headers,
|
||||
# headers=json.loads(json.dumps(request.headers)),
|
||||
)
|
||||
|
||||
print('living_spaces', living_spaces)
|
||||
occupants_selection_dict = {}
|
||||
for living_space in living_spaces:
|
||||
build_parts_selection = BuildParts.filter_active(
|
||||
@@ -93,7 +96,7 @@ def save_access_token_to_redis(
|
||||
detail=dict(
|
||||
message="No build Part is found for the living space. Please contact the admin."
|
||||
),
|
||||
headers=request.headers,
|
||||
# headers=json.loads(json.dumps(request.headers)),
|
||||
)
|
||||
build_part = build_parts_selection.get(1)
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from fastapi import HTTPException, status
|
||||
from fastapi.requests import Request
|
||||
|
||||
|
||||
def parse_token_object_to_dict(request: Request): # from requests import Request
|
||||
def parse_token_object_to_dict(request): # from requests import Request
|
||||
import api_events.events as events
|
||||
|
||||
from api_services.redis.functions import get_object_via_access_key
|
||||
from databases import EndpointRestriction, Events
|
||||
import api_events.events as events
|
||||
|
||||
if valid_token := get_object_via_access_key(request=request):
|
||||
endpoint_name = str(request.url).replace(str(request.base_url), "/")
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import json
|
||||
import typing
|
||||
|
||||
from fastapi import status
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
from .conn import redis_cli
|
||||
|
||||
from api_configs import Auth
|
||||
@@ -13,6 +10,9 @@ from api_objects import EmployeeTokenObject, OccupantTokenObject
|
||||
def get_object_via_access_key(
|
||||
request,
|
||||
) -> typing.Union[EmployeeTokenObject, OccupantTokenObject, None]:
|
||||
from fastapi import status
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
if not hasattr(request, "headers"):
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
@@ -28,6 +28,7 @@ def get_object_via_access_key(
|
||||
already_tokens = redis_cli.scan_iter(
|
||||
match=str(request.headers.get(Auth.ACCESS_TOKEN_TAG) + ":*")
|
||||
)
|
||||
print('already_tokens', already_tokens)
|
||||
|
||||
if already_tokens := list(already_tokens):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user