mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Preserve continue URL when doing a signed out redirect.
This commit is contained in:
parent
16f16ae9d9
commit
7a81416850
3 changed files with 17 additions and 6 deletions
17
app/app.go
17
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)
|
route := router.Get(routeName)
|
||||||
if route == nil {
|
if route == nil {
|
||||||
return InternalError(
|
return InternalError(
|
||||||
|
|
@ -112,11 +112,18 @@ func RedirectToRoute(routeName string) *AppError {
|
||||||
errors.New("Could not get route URL"),
|
errors.New("Could not get route URL"),
|
||||||
fmt.Sprintf("Could not get route URL for route '%s'", routeName))
|
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())
|
return RedirectToUrl(routeUrl.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NotSignedIn() *AppError {
|
func NotSignedIn(r *http.Request) *AppError {
|
||||||
return RedirectToRoute("index")
|
return RedirectToRoute("index", map[string]string{"continue_url": r.URL.String()})
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppHandler func(http.ResponseWriter, *http.Request) *AppError
|
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)
|
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
|
||||||
userId, ok := session.Values[sessionConfig.UserIdKey].(int)
|
userId, ok := session.Values[sessionConfig.UserIdKey].(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
handleAppError(NotSignedIn(), w, r)
|
handleAppError(NotSignedIn(r), w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c := appengine.NewContext(r)
|
c := appengine.NewContext(r)
|
||||||
account, err := getAccount(c, userId)
|
account, err := getAccount(c, userId)
|
||||||
if account == nil || err != nil {
|
if account == nil || err != nil {
|
||||||
handleAppError(NotSignedIn(), w, r)
|
handleAppError(NotSignedIn(r), w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,10 @@ func indexHandler(w http.ResponseWriter, r *http.Request) *AppError {
|
||||||
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
|
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
|
||||||
userId, ok := session.Values[sessionConfig.UserIdKey].(int)
|
userId, ok := session.Values[sessionConfig.UserIdKey].(int)
|
||||||
if !ok {
|
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)
|
c := appengine.NewContext(r)
|
||||||
account, err := getAccount(c, userId)
|
account, err := getAccount(c, userId)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
<form id="sign-in-form" method="POST" action="{{routeUrl "sign-in"}}">
|
<form id="sign-in-form" method="POST" action="{{routeUrl "sign-in"}}">
|
||||||
<span class="mega-octicon octicon-mark-github"></span>
|
<span class="mega-octicon octicon-mark-github"></span>
|
||||||
|
<input type="hidden" name="continue_url" value="{{.ContinueUrl}}">
|
||||||
<input type="submit" class="action-button" value="Sign In with GitHub">
|
<input type="submit" class="action-button" value="Sign In with GitHub">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="include_private" value="1" checked>
|
<input type="checkbox" name="include_private" value="1" checked>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue