auth.go 739 B

123456789101112131415161718192021222324252627282930313233
  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. "miniflux.app/v2/internal/errors"
  7. )
  8. // AuthForm represents the authentication form.
  9. type AuthForm struct {
  10. Username string
  11. Password string
  12. }
  13. // Validate makes sure the form values are valid.
  14. func (a AuthForm) Validate() error {
  15. if a.Username == "" || a.Password == "" {
  16. return errors.NewLocalizedError("error.fields_mandatory")
  17. }
  18. return nil
  19. }
  20. // NewAuthForm returns a new AuthForm.
  21. func NewAuthForm(r *http.Request) *AuthForm {
  22. return &AuthForm{
  23. Username: r.FormValue("username"),
  24. Password: r.FormValue("password"),
  25. }
  26. }