diff --git a/src/hmnurl/hmnurl_test.go b/src/hmnurl/hmnurl_test.go index b772c821..31764950 100644 --- a/src/hmnurl/hmnurl_test.go +++ b/src/hmnurl/hmnurl_test.go @@ -63,7 +63,7 @@ func TestLoginPage(t *testing.T) { } func TestLogoutAction(t *testing.T) { - AssertRegexMatch(t, BuildLogoutAction(), RegexLogoutAction, nil) + AssertRegexMatch(t, BuildLogoutAction(""), RegexLogoutAction, nil) } func TestRegister(t *testing.T) { diff --git a/src/hmnurl/urls.go b/src/hmnurl/urls.go index 9fe16163..fee567d8 100644 --- a/src/hmnurl/urls.go +++ b/src/hmnurl/urls.go @@ -66,9 +66,12 @@ func BuildLoginPage(redirectTo string) string { var RegexLogoutAction = regexp.MustCompile("^/logout$") -func BuildLogoutAction() string { +func BuildLogoutAction(redir string) string { defer CatchPanic() - return Url("/logout", nil) + if redir == "" { + redir = "/" + } + return Url("/logout", []Q{{"redirect", redir}}) } var RegexRegister = regexp.MustCompile("^/_register$") diff --git a/src/templates/src/include/header.html b/src/templates/src/include/header.html index 90db2838..ca43b20d 100644 --- a/src/templates/src/include/header.html +++ b/src/templates/src/include/header.html @@ -5,7 +5,7 @@ Admin {{ end }} {{ .User.Username }} - Logout + Log Out {{ else }} Register Log in @@ -23,6 +23,7 @@ {{/* TODO: Forgot password flow? Or just on standalone page? */}} +
diff --git a/src/templates/types.go b/src/templates/types.go index d3209d13..3f12f4f0 100644 --- a/src/templates/types.go +++ b/src/templates/types.go @@ -14,6 +14,7 @@ type BaseData struct { BodyClasses []string Breadcrumbs []Breadcrumb + CurrentUrl string LoginPageUrl string ProjectCSSUrl string diff --git a/src/website/login.go b/src/website/login.go index bc7e7b25..4fe2a478 100644 --- a/src/website/login.go +++ b/src/website/login.go @@ -91,7 +91,12 @@ func Logout(c *RequestContext) ResponseData { } } - res := c.Redirect("/", http.StatusSeeOther) // TODO: Redirect to the page the user was currently on, or if not authorized to view that page, immediately to the home page. + redir := c.Req.URL.Query().Get("redirect") + if redir == "" { + redir = "/" + } + + res := c.Redirect(redir, http.StatusSeeOther) res.SetCookie(auth.DeleteSessionCookie) return res diff --git a/src/website/routes.go b/src/website/routes.go index 6c2744ad..ffe3d880 100644 --- a/src/website/routes.go +++ b/src/website/routes.go @@ -135,17 +135,21 @@ func getBaseData(c *RequestContext) templates.BaseData { } return templates.BaseData{ - Project: templates.ProjectToTemplate(c.CurrentProject, c.Theme), + Theme: c.Theme, + + CurrentUrl: c.FullUrl(), LoginPageUrl: hmnurl.BuildLoginPage(c.FullUrl()), - User: templateUser, - Theme: c.Theme, ProjectCSSUrl: hmnurl.BuildProjectCSS(c.CurrentProject.Color1), + + Project: templates.ProjectToTemplate(c.CurrentProject, c.Theme), + User: templateUser, + IsProjectPage: !c.CurrentProject.IsHMN(), Header: templates.Header{ AdminUrl: hmnurl.BuildHomepage(), // TODO(asaf) UserSettingsUrl: hmnurl.BuildHomepage(), // TODO(asaf) LoginActionUrl: hmnurl.BuildLoginAction(c.FullUrl()), - LogoutActionUrl: hmnurl.BuildLogoutAction(), + LogoutActionUrl: hmnurl.BuildLogoutAction(c.FullUrl()), RegisterUrl: hmnurl.BuildHomepage(), // TODO(asaf) HMNHomepageUrl: hmnurl.BuildHomepage(), ProjectHomepageUrl: hmnurl.BuildProjectHomepage(c.CurrentProject.Slug),