diff --git a/pkg/api/api.go b/pkg/api/api.go index d0d1e6ec9d7..949c7f7534e 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -23,6 +23,7 @@ var plog = log.New("api") func (hs *HTTPServer) registerRoutes() { reqNoAuth := middleware.NoAuth() reqSignedIn := middleware.ReqSignedIn + reqNotSignedIn := middleware.ReqNotSignedIn reqSignedInNoAnonymous := middleware.ReqSignedInNoAnonymous reqGrafanaAdmin := middleware.ReqGrafanaAdmin reqEditorRole := middleware.ReqEditorRole @@ -112,7 +113,7 @@ func (hs *HTTPServer) registerRoutes() { r.Post("/api/user/invite/complete", bind(dtos.CompleteInviteForm{}), routing.Wrap(hs.CompleteInvite)) // reset password - r.Get("/user/password/send-reset-email", hs.Index) + r.Get("/user/password/send-reset-email", reqNotSignedIn, hs.Index) r.Get("/user/password/reset", hs.Index) r.Post("/api/user/password/send-reset-email", bind(dtos.SendResetPasswordEmailForm{}), routing.Wrap(SendResetPasswordEmail)) diff --git a/pkg/middleware/auth.go b/pkg/middleware/auth.go index 8841250eafe..267a69c87a6 100644 --- a/pkg/middleware/auth.go +++ b/pkg/middleware/auth.go @@ -161,6 +161,12 @@ func SnapshotPublicModeOrSignedIn(cfg *setting.Cfg) macaron.Handler { } } +func ReqNotSignedIn(c *models.ReqContext) { + if c.IsSignedIn { + c.Redirect(setting.AppSubUrl + "/") + } +} + // NoAuth creates a middleware that doesn't require any authentication. // If forceLogin param is set it will redirect the user to the login page. func NoAuth() macaron.Handler {