Use the register destination when coming from the login page

This commit is contained in:
Ben Visness 2022-08-13 15:07:37 -05:00
parent 782db18cc3
commit d7b43fdea0
3 changed files with 17 additions and 10 deletions

View File

@ -105,9 +105,13 @@ func BuildLogoutAction(redir string) string {
var RegexRegister = regexp.MustCompile("^/register$")
func BuildRegister() string {
func BuildRegister(destination string) string {
defer CatchPanic()
return Url("/register", nil)
var query []Q
if destination != "" {
query = append(query, Q{"destination", destination})
}
return Url("/register", query)
}
var RegexRegistrationSuccess = regexp.MustCompile("^/registered_successfully$")
@ -341,7 +345,7 @@ func BuildProjectNew() string {
func BuildProjectNewJam() string {
defer CatchPanic()
return Url("/p/new", []Q{Q{Name: "jam", Value: "1"}})
return Url("/p/new", []Q{{Name: "jam", Value: "1"}})
}
var RegexPersonalProject = regexp.MustCompile("^/p/(?P<projectid>[0-9]+)(/(?P<projectslug>[a-zA-Z0-9-]+))?")

View File

@ -33,11 +33,13 @@ func LoginPage(c *RequestContext) ResponseData {
return c.RejectRequest("You are already logged in.")
}
redirect := c.Req.URL.Query().Get("redirect")
var res ResponseData
res.MustWriteTemplate("auth_login.html", LoginPageData{
BaseData: getBaseData(c, "Log in", nil),
RedirectUrl: c.Req.URL.Query().Get("redirect"),
RegisterUrl: hmnurl.BuildRegister(),
RedirectUrl: redirect,
RegisterUrl: hmnurl.BuildRegister(redirect),
ForgotPasswordUrl: hmnurl.BuildRequestPasswordReset(),
}, c.Perf)
return res
@ -387,6 +389,7 @@ func EmailConfirmationSubmit(c *RequestContext) ResponseData {
BaseData: baseData,
Token: token,
Username: username,
DestinationURL: destination,
}, c.Perf)
return res
}

View File

@ -67,7 +67,7 @@ func getBaseData(c *RequestContext, title string, breadcrumbs []templates.Breadc
LoginActionUrl: hmnurl.BuildLoginAction(c.FullUrl()),
LogoutActionUrl: hmnurl.BuildLogoutAction(c.FullUrl()),
ForgotPasswordUrl: hmnurl.BuildRequestPasswordReset(),
RegisterUrl: hmnurl.BuildRegister(),
RegisterUrl: hmnurl.BuildRegister(""),
HMNHomepageUrl: hmnurl.BuildHomepage(),
ProjectIndexUrl: hmnurl.BuildProjectIndex(1),