From f0b5c3b90a9ca4ef7c4759d49e91b3da80ff9c72 Mon Sep 17 00:00:00 2001
From: Unknwon <u@gogs.io>
Date: Sat, 27 Aug 2016 15:07:02 -0700
Subject: [PATCH] #3448 redirect if any after sign in

---
 routers/user/auth.go | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/routers/user/auth.go b/routers/user/auth.go
index 40687fca6f..031ac026bd 100644
--- a/routers/user/auth.go
+++ b/routers/user/auth.go
@@ -76,8 +76,15 @@ func SignIn(ctx *context.Context) {
 		return
 	}
 
+	redirectTo := ctx.Query("redirect_to")
+	if len(redirectTo) > 0 {
+		ctx.SetCookie("redirect_to", redirectTo, 0, setting.AppSubUrl)
+	} else {
+		redirectTo, _ = url.QueryUnescape(ctx.GetCookie("redirect_to"))
+	}
+
 	if isSucceed {
-		if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
+		if len(redirectTo) > 0 {
 			ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl)
 			ctx.Redirect(redirectTo)
 		} else {