mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
feat: Add option to disable local auth form
This commit is contained in:
parent
59dac15bdf
commit
770cc1dbb3
10 changed files with 68 additions and 11 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"miniflux.app/v2/internal/config"
|
||||
"miniflux.app/v2/internal/locale"
|
||||
"miniflux.app/v2/internal/model"
|
||||
)
|
||||
|
@ -86,7 +87,9 @@ func ExtractMarkAsReadBehavior(behavior MarkReadBehavior) (markReadOnView, markR
|
|||
|
||||
// Merge updates the fields of the given user.
|
||||
func (s *SettingsForm) Merge(user *model.User) *model.User {
|
||||
user.Username = s.Username
|
||||
if !config.Opts.DisableLocalAuth() {
|
||||
user.Username = s.Username
|
||||
}
|
||||
user.Theme = s.Theme
|
||||
user.Language = s.Language
|
||||
user.Timezone = s.Timezone
|
||||
|
@ -120,7 +123,7 @@ func (s *SettingsForm) Merge(user *model.User) *model.User {
|
|||
|
||||
// Validate makes sure the form values are valid.
|
||||
func (s *SettingsForm) Validate() *locale.LocalizedError {
|
||||
if s.Username == "" || s.Theme == "" || s.Language == "" || s.Timezone == "" || s.EntryDirection == "" || s.DisplayMode == "" || s.DefaultHomePage == "" {
|
||||
if (s.Username == "" && !config.Opts.DisableLocalAuth()) || s.Theme == "" || s.Language == "" || s.Timezone == "" || s.EntryDirection == "" || s.DisplayMode == "" || s.DefaultHomePage == "" {
|
||||
return locale.NewLocalizedError("error.settings_mandatory_fields")
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,18 @@ import (
|
|||
func (h *handler) checkLogin(w http.ResponseWriter, r *http.Request) {
|
||||
clientIP := request.ClientIP(r)
|
||||
sess := session.New(h.store, request.SessionID(r))
|
||||
authForm := form.NewAuthForm(r)
|
||||
|
||||
view := view.New(h.tpl, r, sess)
|
||||
|
||||
if config.Opts.DisableLocalAuth() {
|
||||
slog.Warn("blocking local auth login attempt, local auth is disabled",
|
||||
slog.String("client_ip", clientIP),
|
||||
slog.String("user_agent", r.UserAgent()),
|
||||
)
|
||||
html.OK(w, r, view.Render("login"))
|
||||
return
|
||||
}
|
||||
|
||||
authForm := form.NewAuthForm(r)
|
||||
view.Set("errorMessage", locale.NewLocalizedError("error.bad_credentials").Translate(request.UserLanguage(r)))
|
||||
view.Set("form", authForm)
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/v2/internal/config"
|
||||
"miniflux.app/v2/internal/http/request"
|
||||
"miniflux.app/v2/internal/http/response/html"
|
||||
"miniflux.app/v2/internal/http/route"
|
||||
|
@ -15,6 +16,14 @@ import (
|
|||
)
|
||||
|
||||
func (h *handler) oauth2Unlink(w http.ResponseWriter, r *http.Request) {
|
||||
if config.Opts.DisableLocalAuth() {
|
||||
slog.Warn("blocking oauth2 unlink attempt, local auth is disabled",
|
||||
slog.String("user_agent", r.UserAgent()),
|
||||
)
|
||||
html.Redirect(w, r, route.Path(h.router, "login"))
|
||||
return
|
||||
}
|
||||
|
||||
printer := locale.NewPrinter(request.UserLanguage(r))
|
||||
provider := request.RouteStringParam(r, "provider")
|
||||
if provider == "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue