Ajout d'une page 'Non autorisée' et redirection automatique vers celle ci en cas d'accès via un compte non autorisé

This commit is contained in:
2020-10-12 10:05:04 +02:00
parent 7a6eedab9d
commit 0859202987
4 changed files with 52 additions and 10 deletions

View File

@ -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
}

View File

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