Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login redirection links #17451

Merged
merged 6 commits into from
Oct 28, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/base/head_navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
{{svg "octicon-person"}} {{.i18n.Tr "register"}}
</a>
{{end}}
<a class="item{{if .PageIsSignIn}} active{{end}}" rel="nofollow" href="{{AppSubUrl}}/user/login?redirect_to={{.CurrentURL}}">
<a class="item{{if .PageIsSignIn}} active{{end}}" rel="nofollow" href="{{AppSubUrl}}/user/login{{if not .PageIsSignIn}}?redirect_to={{.CurrentURL}}{{end}}">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider href="{{if not .PageIsSignIn}}{{AppSubUrl}}/user/login?redirect_to={{end}}{{.CurrentURL}}" to keep the original link?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds very cool, but it doesn't work:

package main

import (
	"html/template"
	"log"
	"os"
)

func main() {
	tplStr := `
	<a href="{{.url}}">
	<a href="?redirect={{.url}}">
	<a href="{{if true}}?{{end}}redirect={{.url}}">
	<a href="{{if not true}}?{{end}}redirect={{.url}}">
`
	tpl := template.Must(template.New("tplName").Parse(tplStr))
	err := tpl.Execute(os.Stdout, map[string]interface{}{"url":"/p?a=1&b=2#h", "true": true})
	log.Printf("err = %v", err)
}

error: 2021/10/28 17:23:38 err = html/template:tplName:4:40: {{.url}} appears in an ambiguous context within a URL

{{svg "octicon-sign-in"}} {{.i18n.Tr "sign_in"}}
</a>
</div><!-- end anonymous right menu -->
Expand Down