这是indexloc提供的服务,不要输入任何密码
Skip to content
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
1 change: 1 addition & 0 deletions internal/template/templates/views/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{{ if not disableLocalAuth }}
<form action="{{ route "checkLogin" }}" method="post">
<input type="hidden" name="csrf" value="{{ .csrf }}">
<input type="hidden" name="redirect_url" value="{{ .redirectURL }}">

{{ if .errorMessage }}
<div role="alert" class="alert alert-error">{{ .errorMessage }}</div>
Expand Down
10 changes: 10 additions & 0 deletions internal/ui/login_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ui // import "miniflux.app/v2/internal/ui"
import (
"log/slog"
"net/http"
"net/url"

"miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/http/cookie"
Expand All @@ -22,6 +23,8 @@ func (h *handler) checkLogin(w http.ResponseWriter, r *http.Request) {
clientIP := request.ClientIP(r)
sess := session.New(h.store, request.SessionID(r))
view := view.New(h.tpl, r, sess)
redirectURL := r.FormValue("redirect_url")
view.Set("redirectURL", redirectURL)

if config.Opts.DisableLocalAuth() {
slog.Warn("blocking local auth login attempt, local auth is disabled",
Expand Down Expand Up @@ -93,5 +96,12 @@ func (h *handler) checkLogin(w http.ResponseWriter, r *http.Request) {
config.Opts.BasePath(),
))

if redirectURL != "" {
if parsedURL, err := url.Parse(redirectURL); err == nil && !parsedURL.IsAbs() {
html.Redirect(w, r, redirectURL)
return
}
}

html.Redirect(w, r, route.Path(h.router, user.DefaultHomePage))
}
2 changes: 2 additions & 0 deletions internal/ui/login_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ func (h *handler) showLoginPage(w http.ResponseWriter, r *http.Request) {

sess := session.New(h.store, request.SessionID(r))
view := view.New(h.tpl, r, sess)
redirectURL := request.QueryStringParam(r, "redirect_url", "")
view.Set("redirectURL", redirectURL)
html.OK(w, r, view.Render("login"))
}
7 changes: 6 additions & 1 deletion internal/ui/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"log/slog"
"net/http"
"net/url"

"miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/crypto"
Expand Down Expand Up @@ -42,7 +43,11 @@ func (m *middleware) handleUserSession(next http.Handler) http.Handler {
slog.Debug("Redirecting to login page because no user session has been found",
slog.String("url", r.RequestURI),
)
html.Redirect(w, r, route.Path(m.router, "login"))
loginURL, _ := url.Parse(route.Path(m.router, "login"))
values := loginURL.Query()
values.Set("redirect_url", r.RequestURI)
loginURL.RawQuery = values.Encode()
html.Redirect(w, r, loginURL.String())
}
} else {
slog.Debug("User session found",
Expand Down
Loading