From b2dcf06b6017aab7719ccf3a8e4de389c9b6c1b7 Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Tue, 10 Nov 2020 22:36:35 +0000 Subject: [PATCH] Backend: Adds route for well-known change password URL (#28788) * Backend: Adds route for well-known change password URL * Include 'dashboard/new' in backend routes * Move index route handler registration out of "not logged in views" section Co-authored-by: Arve Knudsen --- pkg/api/api.go | 5 +++-- pkg/api/http_server.go | 2 +- pkg/api/user.go | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index 7986b0be5bf..51ea0904864 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -33,8 +33,10 @@ func (hs *HTTPServer) registerRoutes() { r.Get("/invite/:code", hs.Index) // authed views + r.Get("/", reqSignedIn, hs.Index) r.Get("/profile/", reqSignedIn, hs.Index) r.Get("/profile/password", reqSignedIn, hs.Index) + r.Get("/.well-known/change-password", redirectToChangePassword) r.Get("/profile/switch-org/:id", reqSignedIn, hs.ChangeActiveOrgAndRedirectToHome) r.Get("/org/", reqOrgAdmin, hs.Index) r.Get("/org/new", reqGrafanaAdmin, hs.Index) @@ -71,6 +73,7 @@ func (hs *HTTPServer) registerRoutes() { r.Get("/d/:uid", reqSignedIn, redirectFromLegacyPanelEditURL, hs.Index) r.Get("/dashboard/db/:slug", reqSignedIn, redirectFromLegacyDashboardURL, hs.Index) r.Get("/dashboard/script/*", reqSignedIn, hs.Index) + r.Get("/dashboard/new", reqSignedIn, hs.Index) r.Get("/dashboard-solo/snapshot/*", hs.Index) r.Get("/d-solo/:uid/:slug", reqSignedIn, hs.Index) r.Get("/d-solo/:uid", reqSignedIn, hs.Index) @@ -442,6 +445,4 @@ func (hs *HTTPServer) registerRoutes() { r.Get("/api/snapshots/:key", Wrap(GetDashboardSnapshot)) r.Get("/api/snapshots-delete/:deleteKey", reqSnapshotPublicModeOrSignedIn, Wrap(DeleteDashboardSnapshotByDeleteKey)) r.Delete("/api/snapshots/:key", reqEditorRole, Wrap(DeleteDashboardSnapshot)) - - r.Get("/*", reqSignedIn, hs.Index) } diff --git a/pkg/api/http_server.go b/pkg/api/http_server.go index b5e6cf24b76..ad95abe987c 100644 --- a/pkg/api/http_server.go +++ b/pkg/api/http_server.go @@ -288,7 +288,7 @@ func (hs *HTTPServer) applyRoutes() { // then custom app proxy routes hs.initAppPluginRoutes(hs.macaron) // lastly not found route - hs.macaron.NotFound(hs.NotFoundHandler) + hs.macaron.NotFound(middleware.ReqSignedIn, hs.NotFoundHandler) } func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() { diff --git a/pkg/api/user.go b/pkg/api/user.go index 6649752f7ab..724a5bb55c9 100644 --- a/pkg/api/user.go +++ b/pkg/api/user.go @@ -250,6 +250,11 @@ func ChangeUserPassword(c *models.ReqContext, cmd models.ChangeUserPasswordComma return Success("User password changed") } +// redirectToChangePassword handles GET /.well-known/change-password. +func redirectToChangePassword(c *models.ReqContext) { + c.Redirect("/profile/password", 302) +} + // GET /api/users func SearchUsers(c *models.ReqContext) Response { query, err := searchUser(c)