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

(NOBIDS) remember page user tried to access before login #2973

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ func Login(w http.ResponseWriter, r *http.Request) {
RecaptchaKey: utils.Config.Frontend.RecaptchaSiteKey,
}

if redirect := q.Get("redirect"); redirect != "" {
http.SetCookie(w, &http.Cookie{
Name: "redirect-after",
Value: redirect,
MaxAge: 300,
})
} else if redirect := q.Get("redirect_uri"); redirect != "" {
http.SetCookie(w, &http.Cookie{
Name: "redirect-after",
Value: redirect + "&state=" + q.Get("state"),
MaxAge: 300,
})
}

redirectData := struct {
Redirect_uri string
State string
Expand Down Expand Up @@ -339,6 +353,12 @@ func LoginPost(w http.ResponseWriter, r *http.Request) {
return
}

cookie, err := r.Cookie("redirect-after")
if err == nil && cookie.Value != "" {
http.Redirect(w, r, cookie.Value, http.StatusSeeOther)
return
}

// Index(w, r)
http.Redirect(w, r, "/user/notifications", http.StatusSeeOther)
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func UserAuthMiddleware(next http.Handler) http.Handler {
user := getUser(r)
if !user.Authenticated {
utils.SetFlash(w, r, authSessionName, "Error: Please login first")
http.Redirect(w, r, "/login", http.StatusSeeOther)
http.Redirect(w, r, "/login?redirect="+r.URL.Path, http.StatusSeeOther)
return
}
next.ServeHTTP(w, r)
Expand Down
Loading