4
0

auth.go 805 B

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package form // import "miniflux.app/v2/internal/ui/form"
  4. import (
  5. "net/http"
  6. "strings"
  7. "miniflux.app/v2/internal/locale"
  8. )
  9. // authForm represents the authentication form.
  10. type authForm struct {
  11. Username string
  12. Password string
  13. }
  14. // Validate makes sure the form values are valid.
  15. func (a authForm) Validate() *locale.LocalizedError {
  16. if a.Username == "" || a.Password == "" {
  17. return locale.NewLocalizedError("error.fields_mandatory")
  18. }
  19. return nil
  20. }
  21. // NewAuthForm returns a new AuthForm.
  22. func NewAuthForm(r *http.Request) *authForm {
  23. return &authForm{
  24. Username: strings.TrimSpace(r.FormValue("username")),
  25. Password: strings.TrimSpace(r.FormValue("password")),
  26. }
  27. }