From 08592029878a64956c544d87dcf9dabf1ed24f13 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 12 Oct 2020 10:05:04 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20page=20'Non=20autoris=C3=A9e'?= =?UTF-8?q?=20et=20redirection=20automatique=20vers=20celle=20ci=20en=20ca?= =?UTF-8?q?s=20d'acc=C3=A8s=20via=20un=20compte=20non=20autoris=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/App.tsx | 2 + .../UnauthorizedPage/UnauthorizedPage.tsx | 37 +++++++++++++++++++ internal/route/login.go | 8 +--- internal/route/mount.go | 15 ++++++-- 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 client/src/components/UnauthorizedPage/UnauthorizedPage.tsx diff --git a/client/src/components/App.tsx b/client/src/components/App.tsx index 9373b32..fe5eaea 100644 --- a/client/src/components/App.tsx +++ b/client/src/components/App.tsx @@ -13,6 +13,7 @@ import { Modal } from './Modal'; import { createClient } from '../util/apollo'; import { ApolloProvider } from '@apollo/client'; import { LogoutPage } from './LogoutPage'; +import { UnauthorizedPage } from './UnauthorizedPage/UnauthorizedPage'; export interface AppProps { @@ -41,6 +42,7 @@ export const App: FunctionComponent = () => { + diff --git a/client/src/components/UnauthorizedPage/UnauthorizedPage.tsx b/client/src/components/UnauthorizedPage/UnauthorizedPage.tsx new file mode 100644 index 0000000..4ad4db2 --- /dev/null +++ b/client/src/components/UnauthorizedPage/UnauthorizedPage.tsx @@ -0,0 +1,37 @@ +import React, { FunctionComponent } from 'react'; +import { Config } from '../../config'; +import { Page } from '../Page'; + +export interface UnauthorizedPageProps { + +} + +export const UnauthorizedPage:FunctionComponent = () => { + return ( + +
+
+
+
+
+
+

Non autorisé

+
+
+

Vous n'êtes pas autorisé à accéder à cette page.

+
+

Votre compte est peut être désactivé, votre adresse courriel ne fait peut être + pas partie des domaines autorisés ou vous n'avez peut être pas les droits nécessaires pour effectuer cette opération.

+ + +
+
+
+
+
+
+
+ ); +} \ No newline at end of file diff --git a/internal/route/login.go b/internal/route/login.go index 4582a45..158d016 100644 --- a/internal/route/login.go +++ b/internal/route/login.go @@ -1,7 +1,6 @@ package route import ( - "fmt" "net/http" "forge.cadoles.com/Cadoles/daddy/internal/auth" @@ -80,11 +79,8 @@ func handleLoginCallback(w http.ResponseWriter, r *http.Request) { } if !authorized { - message := fmt.Sprintf( - "You are not authorized to access this application. Disconnect by navigating to %s.", - "http://"+r.Host+"/logout", - ) - http.Error(w, message, http.StatusForbidden) + redirectURL := conf.HTTP.FrontendURL + "/unauthorized" + http.Redirect(w, r, redirectURL, http.StatusTemporaryRedirect) return } diff --git a/internal/route/mount.go b/internal/route/mount.go index b295101..1d047a4 100644 --- a/internal/route/mount.go +++ b/internal/route/mount.go @@ -72,10 +72,17 @@ func Mount(r *chi.Mux, config *config.Config) error { } // List of paths handled directly by the client - r.Get("/workgroups/*", serveClientIndex) - r.Get("/profile", serveClientIndex) - r.Get("/dashboard", serveClientIndex) - r.Get("/decisions/*", serveClientIndex) + clientRoutes := []string{ + "/workgroups/*", + "/profile", + "/dashboard", + "/decisions/*", + "/unauthorized", + } + + for _, cr := range clientRoutes { + r.Get(cr, serveClientIndex) + } // Serve static files notFoundHandler := r.NotFoundHandler() -- 2.17.1