diff options
author | Lauris BH <lauris@nix.lv> | 2018-03-15 23:13:34 +0200 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2018-03-15 22:13:34 +0100 |
commit | 7b2b900e13612f565051c64374b788b0c8a82751 (patch) | |
tree | d5d35b485ea898ea13fbf2eac9f879e311ef8ac8 /routers/user | |
parent | a2a49c93c78a81d1eaa6b0eaf84a0c3f4bcd2487 (diff) | |
download | gitea-7b2b900e13612f565051c64374b788b0c8a82751.tar.gz gitea-7b2b900e13612f565051c64374b788b0c8a82751.zip |
Refactor and simplify redirect to url (#3674)
Diffstat (limited to 'routers/user')
-rw-r--r-- | routers/user/auth.go | 12 | ||||
-rw-r--r-- | routers/user/auth_openid.go | 8 | ||||
-rw-r--r-- | routers/user/profile.go | 6 |
3 files changed, 7 insertions, 19 deletions
diff --git a/routers/user/auth.go b/routers/user/auth.go index 6edcb914b1..d44939f50d 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -93,12 +93,8 @@ func checkAutoLogin(ctx *context.Context) bool { } if isSucceed { - if len(redirectTo) > 0 { - ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL) - ctx.Redirect(redirectTo) - } else { - ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL)) - } + ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL) + ctx.RedirectToFirst(redirectTo, setting.AppSubURL+string(setting.LandingPageURL)) return true } @@ -350,7 +346,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 { ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL) if obeyRedirect { - ctx.Redirect(redirectTo) + ctx.RedirectToFirst(redirectTo) } return } @@ -439,7 +435,7 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 { ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL) - ctx.Redirect(redirectTo) + ctx.RedirectToFirst(redirectTo) return } diff --git a/routers/user/auth_openid.go b/routers/user/auth_openid.go index 7df40bcc98..9fe3424aae 100644 --- a/routers/user/auth_openid.go +++ b/routers/user/auth_openid.go @@ -50,12 +50,8 @@ func SignInOpenID(ctx *context.Context) { } if isSucceed { - if len(redirectTo) > 0 { - ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL) - ctx.Redirect(redirectTo) - } else { - ctx.Redirect(setting.AppSubURL + "/") - } + ctx.SetCookie("redirect_to", "", -1, setting.AppSubURL) + ctx.RedirectToFirst(redirectTo) return } diff --git a/routers/user/profile.go b/routers/user/profile.go index d63f84afd3..4c5cbf5081 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -271,9 +271,5 @@ func Action(ctx *context.Context) { return } - redirectTo := ctx.Query("redirect_to") - if len(redirectTo) == 0 { - redirectTo = u.HomeLink() - } - ctx.Redirect(redirectTo) + ctx.RedirectToFirst(ctx.Query("redirect_to"), u.HomeLink()) } |