Make login and logout preserve what page you're on
This commit is contained in:
parent
b6c611004c
commit
e2f85708db
|
@ -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) {
|
||||
|
|
|
@ -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$")
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<a class="admin-panel" href="{{ .Header.AdminUrl }}"><span class="icon-settings"> Admin</span></a>
|
||||
{{ end }}
|
||||
<a class="username settings" href="{{ .Header.MemberSettingsUrl }}"><span class="icon-settings"></span> {{ .User.Username }}</a>
|
||||
<a class="logout" href="{{ .Header.LogoutActionUrl }}"><span class="icon-logout"></span> Logout</a>
|
||||
<a class="logout" href="{{ .Header.LogoutActionUrl }}"><span class="icon-logout"></span> Log Out</a>
|
||||
{{ else }}
|
||||
<a class="register" id="register-link" href="{{ .Header.RegisterUrl }}">Register</a>
|
||||
<a class="login" id="login-link" href="{{ .LoginPageUrl }}">Log in</a>
|
||||
|
@ -23,6 +23,7 @@
|
|||
</tr>
|
||||
{{/* TODO: Forgot password flow? Or just on standalone page? */}}
|
||||
</table>
|
||||
<input type="hidden" name="redirect" value="{{ $.CurrentUrl }}">
|
||||
<div class="actionbar pt2">
|
||||
<input type="submit" value="Log In" />
|
||||
</div>
|
||||
|
|
|
@ -14,6 +14,7 @@ type BaseData struct {
|
|||
BodyClasses []string
|
||||
Breadcrumbs []Breadcrumb
|
||||
|
||||
CurrentUrl string
|
||||
LoginPageUrl string
|
||||
ProjectCSSUrl string
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -131,17 +131,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)
|
||||
MemberSettingsUrl: 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(), // TODO(asaf)
|
||||
ProjectHomepageUrl: hmnurl.BuildProjectHomepage(c.CurrentProject.Slug),
|
||||
|
|
Loading…
Reference in New Issue