Adding redirecto when login
Cette révision appartient à :
Parent
d4c245e256
révision
d74d337c25
3 fichiers modifiés avec 10 ajouts et 6 suppressions
|
@ -44,7 +44,9 @@ func UserLoginFormHandler(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
loginForm := userValidator.LoginForm{}
|
||||
loginForm := userValidator.LoginForm{
|
||||
RedirectTo: c.DefaultQuery("redirectTo", ""),
|
||||
}
|
||||
formTemplate(c, "site/user/login.jet.html", loginForm)
|
||||
}
|
||||
|
||||
|
@ -238,7 +240,8 @@ func UserLoginPostHandler(c *gin.Context) {
|
|||
if !messages.HasErrors() {
|
||||
_, _, errorUser := cookies.CreateUserAuthentication(c, &b)
|
||||
if errorUser == nil {
|
||||
c.Redirect(http.StatusSeeOther, "/")
|
||||
url := c.DefaultPostForm("redirectTo", "/")
|
||||
c.Redirect(http.StatusSeeOther, url)
|
||||
return
|
||||
}
|
||||
messages.ErrorT(errorUser)
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
<a class="nav-btn" href="/notifications">{{ T("my_notifications")}} <span class="badge">({{ User.GetUnreadNotifications() }})</span></a>
|
||||
<a class="nav-btn" href="/user/{{ User.ID }}/{{ User.Username }}/edit">{{ T("settings")}}</a>
|
||||
{{if User.HasAdmin()}}<a class="nav-btn" href="/mod">{{ T("moderation")}}</a>{{end}}
|
||||
<form action="/logout" method="POST">{{ yield csrf_field() }}<input class="nav-btn" type="submit" name="logout" value="{{ T("sign_out")}}"></form>
|
||||
<form action="/logout" method="POST">{{ yield csrf_field() }}<input type="hidden" value="{{ URL.String() }}" name="redirectTo"><input class="nav-btn" type="submit" name="logout" value="{{ T("sign_out")}}"></form>
|
||||
</div>
|
||||
{{ else }}
|
||||
<a href="/login" class="nav-btn">
|
||||
<a href="/login?redirectTo={{ URL.String() }}" class="nav-btn">
|
||||
{{ T("signin") }}<span class="caret"></span>
|
||||
</a>
|
||||
{{end}}
|
||||
|
|
|
@ -12,8 +12,9 @@ type RegistrationForm struct {
|
|||
|
||||
// LoginForm is used when a user logs in.
|
||||
type LoginForm struct {
|
||||
Username string `validate:"required" json:"username" form:"username"`
|
||||
Password string `validate:"required" json:"password" form:"password"`
|
||||
Username string `validate:"required" json:"username" form:"username"`
|
||||
Password string `validate:"required" json:"password" form:"password"`
|
||||
RedirectTo string `validate:"-" form:"redirectTo" json:"omitempty"`
|
||||
}
|
||||
|
||||
// UserForm is used when updating a user.
|
||||
|
|
Référencer dans un nouveau ticket