diff --git a/app/app.go b/app/app.go index a1f9379..da61cc7 100644 --- a/app/app.go +++ b/app/app.go @@ -99,7 +99,7 @@ func BadRequest(err error, message string) *AppError { } } -func RedirectToRoute(routeName string) *AppError { +func RedirectToRoute(routeName string, queryParameters ...map[string]string) *AppError { route := router.Get(routeName) if route == nil { return InternalError( @@ -112,11 +112,18 @@ func RedirectToRoute(routeName string) *AppError { errors.New("Could not get route URL"), fmt.Sprintf("Could not get route URL for route '%s'", routeName)) } + if len(queryParameters) != 0 { + routeUrlQuery := routeUrl.Query() + for k, v := range queryParameters[0] { + routeUrlQuery.Set(k, v) + } + routeUrl.RawQuery = routeUrlQuery.Encode() + } return RedirectToUrl(routeUrl.String()) } -func NotSignedIn() *AppError { - return RedirectToRoute("index") +func NotSignedIn(r *http.Request) *AppError { + return RedirectToRoute("index", map[string]string{"continue_url": r.URL.String()}) } type AppHandler func(http.ResponseWriter, *http.Request) *AppError @@ -133,13 +140,13 @@ func (fn SignedInAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { session, _ := sessionStore.Get(r, sessionConfig.CookieName) userId, ok := session.Values[sessionConfig.UserIdKey].(int) if !ok { - handleAppError(NotSignedIn(), w, r) + handleAppError(NotSignedIn(r), w, r) return } c := appengine.NewContext(r) account, err := getAccount(c, userId) if account == nil || err != nil { - handleAppError(NotSignedIn(), w, r) + handleAppError(NotSignedIn(r), w, r) return } diff --git a/app/retrogit.go b/app/retrogit.go index e299a04..0787dd3 100644 --- a/app/retrogit.go +++ b/app/retrogit.go @@ -88,7 +88,10 @@ func indexHandler(w http.ResponseWriter, r *http.Request) *AppError { session, _ := sessionStore.Get(r, sessionConfig.CookieName) userId, ok := session.Values[sessionConfig.UserIdKey].(int) if !ok { - return templates["index-signed-out"].Render(w, nil) + data := map[string]interface{}{ + "ContinueUrl": r.FormValue("continue_url"), + } + return templates["index-signed-out"].Render(w, data) } c := appengine.NewContext(r) account, err := getAccount(c, userId) diff --git a/app/templates/index-signed-out.html b/app/templates/index-signed-out.html index f68930e..9bc3b7e 100644 --- a/app/templates/index-signed-out.html +++ b/app/templates/index-signed-out.html @@ -4,6 +4,7 @@
+