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

Fix login redirection links #17451

merged 6 commits into from
Oct 28, 2021

Conversation

qwerty287
Copy link
Contributor

Doesn't add the redirect_to argument if page is login.

fixes #17421 fixes #17444

@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Oct 27, 2021
@lunny
Copy link
Member

lunny commented Oct 27, 2021

And if the login router could check if the redirect_to is itself is better.

@lunny lunny added the type/enhancement An improvement of existing functionality label Oct 27, 2021
@lunny lunny added this to the 1.16.0 milestone Oct 27, 2021
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Oct 27, 2021
@@ -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

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@3fc465b). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17451   +/-   ##
=======================================
  Coverage        ?   45.48%           
=======================================
  Files           ?      791           
  Lines           ?    88697           
  Branches        ?        0           
=======================================
  Hits            ?    40341           
  Misses          ?    41840           
  Partials        ?     6516           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3fc465b...2fc6220. Read the comment docs.

@wxiaoguang wxiaoguang merged commit 54243ee into go-gitea:main Oct 28, 2021
@qwerty287 qwerty287 deleted the login-redirect branch October 28, 2021 13:10
@zeripath zeripath added the backport/done All backports for this PR have been created label Dec 25, 2021
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: zeripath <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
7 participants