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 ( -
-

No Page Selected

-
- ); - } - return ( - <> - {/* Main Content */} -
- -
- - ); -} - -export default MainPage; diff --git a/WebServices/client-frontend/src/app/(AuthLayout)/layout.tsx b/WebServices/client-frontend/src/app/(AuthLayout)/layout.tsx index bf3041e..de7cd56 100644 --- a/WebServices/client-frontend/src/app/(AuthLayout)/layout.tsx +++ b/WebServices/client-frontend/src/app/(AuthLayout)/layout.tsx @@ -6,29 +6,14 @@ export const metadata: Metadata = { description: "WAG Frontend Application", }; -export default function RootLayout({ +export default function AuthLayout({ children, }: { children: React.ReactNode; }) { return ( - - -
-
-

Welcome to evyos

-

- 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. -

-
-
- Loading...
}>{children} -
- - - +
+ Loading...
}>{children} + ); } diff --git a/WebServices/client-frontend/src/app/(AuthLayout)/dashboard/page.tsx b/WebServices/client-frontend/src/app/(DashboardLayout)/dashboard/page.tsx similarity index 79% rename from WebServices/client-frontend/src/app/(AuthLayout)/dashboard/page.tsx rename to WebServices/client-frontend/src/app/(DashboardLayout)/dashboard/page.tsx index edb72ed..ace91b4 100644 --- a/WebServices/client-frontend/src/app/(AuthLayout)/dashboard/page.tsx +++ b/WebServices/client-frontend/src/app/(DashboardLayout)/dashboard/page.tsx @@ -11,26 +11,27 @@ import LeftMenu from "@/components/menu/leftMenu"; export default async function DashboardLayout({ searchParams, }: { - searchParams: { [key: string]: string | undefined }; + searchParams: Promise<{ [key: string]: string | undefined }>; }) { const token_is_valid = await checkAccessTokenIsValid(); - const siteUrlsList = await retrievePageList(); + const siteUrlsList = (await retrievePageList()) || []; if (!token_is_valid) { redirect("/auth/login"); } const lang = "tr"; + const searchParamsInstance = await searchParams; const pageToDirect = await retrievePagebyUrl("/dashboard"); const PageComponent = retrievePage(pageToDirect); return ( <> -
+
{/* Sidebar */} @@ -48,7 +49,7 @@ export default async function DashboardLayout({
- +
diff --git a/WebServices/client-frontend/src/app/(DashboardLayout)/layout.tsx b/WebServices/client-frontend/src/app/(DashboardLayout)/layout.tsx new file mode 100644 index 0000000..a0c4775 --- /dev/null +++ b/WebServices/client-frontend/src/app/(DashboardLayout)/layout.tsx @@ -0,0 +1,19 @@ +import type { Metadata } from "next"; +import { Suspense } from "react"; + +export const metadata: Metadata = { + title: "Create Next App", + description: "Generated by create next app", +}; + +export default function DashLayout({ + children, +}: { + children: React.ReactNode; +}) { + return ( +
+ Loading...
}>{children} + + ); +} diff --git a/WebServices/client-frontend/src/app/layout.tsx b/WebServices/client-frontend/src/app/layout.tsx index 756fcce..4bc3126 100644 --- a/WebServices/client-frontend/src/app/layout.tsx +++ b/WebServices/client-frontend/src/app/layout.tsx @@ -13,7 +13,7 @@ export default function RootLayout({ }>) { return ( - {children} + {children} ); } diff --git a/WebServices/client-frontend/src/components/NavigatePages/app000001.tsx b/WebServices/client-frontend/src/components/NavigatePages/app000001.tsx index 4a856af..1f2ba0c 100644 --- a/WebServices/client-frontend/src/components/NavigatePages/app000001.tsx +++ b/WebServices/client-frontend/src/components/NavigatePages/app000001.tsx @@ -4,15 +4,12 @@ import { PageProps } from "./interFaces"; function App000001({ lang, queryParams }: PageProps) { return ( <> -
+
{/* Sticky Header */}

Dashboard

- {JSON.stringify({ - lang, - queryParams, - })} + {JSON.stringify({ lang, queryParams })}
diff --git a/WebServices/client-frontend/src/components/menu/leftMenu.tsx b/WebServices/client-frontend/src/components/menu/leftMenu.tsx index cbaa308..12acc8c 100644 --- a/WebServices/client-frontend/src/components/menu/leftMenu.tsx +++ b/WebServices/client-frontend/src/components/menu/leftMenu.tsx @@ -13,7 +13,7 @@ async function LeftMenu({ lang: keyof LanguageTranslation; searchParams: { [key: string]: string | string[] | undefined }; }) { - const transformedMenu = transformMenu(pageUuidList); + const transformedMenu = transformMenu(pageUuidList) || []; // Get the menuContext from searchParams without setting a default value const menuContext = searchParams?.menu; @@ -34,68 +34,69 @@ async function LeftMenu({
);