auth.go 762 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package form // import "miniflux.app/ui/form"
  5. import (
  6. "net/http"
  7. "miniflux.app/errors"
  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() error {
  16. if a.Username == "" || a.Password == "" {
  17. return errors.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: r.FormValue("username"),
  25. Password: r.FormValue("password"),
  26. }
  27. }