diff --git a/ApiServices/AuthService/endpoints/auth/route.py b/ApiServices/AuthService/endpoints/auth/route.py index 6e6a28f..04ed1e0 100644 --- a/ApiServices/AuthService/endpoints/auth/route.py +++ b/ApiServices/AuthService/endpoints/auth/route.py @@ -431,3 +431,48 @@ def authentication_page_valid( status_code=status.HTTP_202_ACCEPTED, headers=headers, ) + + +@auth_route.get( + path="/sites/list", + summary="Verify if page is valid returns application avaliable", + description="Verify if page is valid returns application avaliable", +) +def authentication_page_valid( + request: Request, + language: str = Header(None, alias="language"), + domain: str = Header(None, alias="domain"), + tz: str = Header(None, alias="timezone"), +): + """ + Verify if page is valid returns application that can user reach + page: { url = /building/create} + result: { "sites": ['/dashboard', '/building/create'] } + """ + token = request.headers.get(api_config.ACCESS_TOKEN_TAG, None) + headers = { + "language": language or "", + "domain": domain or "", + "eys-ext": f"{str(uuid.uuid4())}", + "tz": tz or "GMT+3", + "token": token, + } + if not domain or not language: + return JSONResponse( + content={"error": "EYS_0003"}, + status_code=status.HTTP_406_NOT_ACCEPTABLE, + headers=headers, + ) + result = AuthHandlers.PageHandlers.retrieve_valid_sites_via_token(access_token=token) + if not result: + return JSONResponse( + content={"error": "EYS_0004"}, + status_code=status.HTTP_406_NOT_ACCEPTABLE, + headers=headers, + ) + return JSONResponse( + content={"sites": result}, + status_code=status.HTTP_202_ACCEPTED, + headers=headers, + ) + diff --git a/ApiServices/AuthService/events/auth/auth.py b/ApiServices/AuthService/events/auth/auth.py index e7fda20..8f2863d 100644 --- a/ApiServices/AuthService/events/auth/auth.py +++ b/ApiServices/AuthService/events/auth/auth.py @@ -367,12 +367,10 @@ class LoginHandler: request: FastAPI request object data: Request body containing login credentials { - "data": { - "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 @@ -709,7 +707,15 @@ class PasswordHandler: class PageHandlers: @classmethod - def retrieve_valid_page_via_token(cls, access_token: str, page_url: str): + def retrieve_valid_page_via_token(cls, access_token: str, page_url: str) -> str: + """ + Retrieve valid page via token. + { + access_token: "string", + page_url: "string" + } + Results: str(application) + """ if result := RedisHandlers.get_object_from_redis(access_token=access_token): if result.is_employee: if application := result.selected_company.reachable_app_codes.get(page_url, None): @@ -720,6 +726,23 @@ class PageHandlers: raise ValueError("EYS_0013") + @classmethod + def retrieve_valid_sites_via_token(cls, access_token: str) -> list: + """ + Retrieve valid pages via token. + { + "access_token": "string" + } + Results: list(sites) + """ + if result := RedisHandlers.get_object_from_redis(access_token=access_token): + if result.is_employee: + return result.selected_company.reachable_app_codes.keys() + elif result.is_occupant: + return result.selected_company.reachable_app_codes.keys() + raise ValueError("EYS_0013") + + class AuthHandlers: LoginHandler: LoginHandler = LoginHandler() diff --git a/WebServices/client-frontend/src/apicalls/cookies/token.tsx b/WebServices/client-frontend/src/apicalls/cookies/token.tsx index 33a1fd0..3fc574c 100644 --- a/WebServices/client-frontend/src/apicalls/cookies/token.tsx +++ b/WebServices/client-frontend/src/apicalls/cookies/token.tsx @@ -2,11 +2,11 @@ import { fetchDataWithToken, fetchData } from "../api-fetcher"; import { baseUrlAuth, tokenSecret } from "../basics"; import { cookies } from "next/headers"; -import NextCrypto from "next-crypto"; +import NextCrypto from "next-crypto"; const checkToken = `${baseUrlAuth}/authentication/token/check`; const pageValid = `${baseUrlAuth}/authentication/page/valid`; -const siteUrls = `${baseUrlAuth}/authentication/page/list`; +const siteUrls = `${baseUrlAuth}/authentication/sites/list`; const nextCrypto = new NextCrypto(tokenSecret); diff --git a/WebServices/client-frontend/src/app/(AuthLayout)/dashboard/main.tsx b/WebServices/client-frontend/src/app/(AuthLayout)/dashboard/main.tsx deleted file mode 100644 index 2d44e16..0000000 --- a/WebServices/client-frontend/src/app/(AuthLayout)/dashboard/main.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import React from "react"; -import retrievePage from "@/components/NavigatePages"; - -function MainPage({ - pageSelected, - lang, -}: { - pageSelected: string | undefined; - lang: string; -}) { - const ComponentPage = retrievePage({ - pageId: pageSelected ?? "", - }); - - if (!ComponentPage) { - return ( -
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do - eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut - enim ad minim veniam, quis nostrud exercitation ullamco laboris - nisi ut aliquip ex ea commodo consequat. -
-