mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
redirect logged in users from /login to home
This commit is contained in:
parent
5998646da5
commit
df85cc9bb1
@ -42,18 +42,18 @@ func (hs *HTTPServer) LoginView(c *m.ReqContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//if !hs.tryLoginUsingRememberCookie(c) {
|
if !c.IsSignedIn {
|
||||||
c.HTML(200, ViewIndex, viewData)
|
c.HTML(200, ViewIndex, viewData)
|
||||||
return
|
return
|
||||||
//}
|
}
|
||||||
|
|
||||||
// if redirectTo, _ := url.QueryUnescape(c.GetCookie("redirect_to")); len(redirectTo) > 0 {
|
if redirectTo, _ := url.QueryUnescape(c.GetCookie("redirect_to")); len(redirectTo) > 0 {
|
||||||
// c.SetCookie("redirect_to", "", -1, setting.AppSubUrl+"/")
|
c.SetCookie("redirect_to", "", -1, setting.AppSubUrl+"/")
|
||||||
// c.Redirect(redirectTo)
|
c.Redirect(redirectTo)
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
|
|
||||||
// c.Redirect(setting.AppSubUrl + "/")
|
c.Redirect(setting.AppSubUrl + "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryOAuthAutoLogin(c *m.ReqContext) bool {
|
func tryOAuthAutoLogin(c *m.ReqContext) bool {
|
||||||
@ -74,48 +74,8 @@ func tryOAuthAutoLogin(c *m.ReqContext) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hs *HTTPServer) tryLoginUsingRememberCookie(c *m.ReqContext) bool {
|
|
||||||
// Check auto-login.
|
|
||||||
uname := c.GetCookie(setting.CookieUserName)
|
|
||||||
if len(uname) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
isSucceed := false
|
|
||||||
defer func() {
|
|
||||||
if !isSucceed {
|
|
||||||
log.Trace("auto-login cookie cleared: %s", uname)
|
|
||||||
c.SetCookie(setting.CookieUserName, "", -1, setting.AppSubUrl+"/")
|
|
||||||
c.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubUrl+"/")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
userQuery := m.GetUserByLoginQuery{LoginOrEmail: uname}
|
|
||||||
if err := bus.Dispatch(&userQuery); err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
user := userQuery.Result
|
|
||||||
|
|
||||||
// validate remember me cookie
|
|
||||||
signingKey := user.Rands + user.Password
|
|
||||||
if len(signingKey) < 10 {
|
|
||||||
c.Logger.Error("Invalid user signingKey")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if val, _ := c.GetSuperSecureCookie(signingKey, setting.CookieRememberName); val != user.Login {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
isSucceed = true
|
|
||||||
hs.loginUserWithUser(user, c)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hs *HTTPServer) LoginAPIPing(c *m.ReqContext) {
|
func (hs *HTTPServer) LoginAPIPing(c *m.ReqContext) {
|
||||||
if !hs.tryLoginUsingRememberCookie(c) {
|
if !c.IsSignedIn || !c.IsAnonymous {
|
||||||
c.JsonApiErr(401, "Unauthorized", nil)
|
c.JsonApiErr(401, "Unauthorized", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user