| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
- // SPDX-License-Identifier: Apache-2.0
- package form // import "miniflux.app/v2/internal/ui/form"
- import (
- "net/http"
- "miniflux.app/v2/internal/locale"
- "miniflux.app/v2/internal/model"
- )
- // AuthSettingsForm represents the authentication settings form.
- type AuthSettingsForm struct {
- Username string
- CurrentPassword string
- Password string
- Confirmation string
- }
- // Merge updates the fields of the given user.
- func (a *AuthSettingsForm) Merge(user *model.User) *model.User {
- user.Username = a.Username
- if a.Password != "" {
- user.Password = a.Password
- }
- return user
- }
- // Validate makes sure the form values are valid.
- func (a *AuthSettingsForm) Validate() *locale.LocalizedError {
- if a.Username == "" {
- return locale.NewLocalizedError("error.settings_mandatory_fields")
- }
- if a.Confirmation == "" {
- // Firefox insists on auto-completing the password field.
- // If the confirmation field is blank, the user probably
- // didn't intend to change their password.
- a.Password = ""
- } else if a.Password != "" {
- if a.Password != a.Confirmation {
- return locale.NewLocalizedError("error.different_passwords")
- }
- }
- return nil
- }
- // NewAuthSettingsForm returns a new AuthSettingsForm.
- func NewAuthSettingsForm(r *http.Request) *AuthSettingsForm {
- return &AuthSettingsForm{
- Username: r.FormValue("username"),
- CurrentPassword: r.FormValue("current_password"),
- Password: r.FormValue("password"),
- Confirmation: r.FormValue("confirmation"),
- }
- }
|