auth.go 567 B

123456789101112131415161718192021222324252627282930
  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
  5. import (
  6. "errors"
  7. "net/http"
  8. )
  9. type AuthForm struct {
  10. Username string
  11. Password string
  12. }
  13. func (a AuthForm) Validate() error {
  14. if a.Username == "" || a.Password == "" {
  15. return errors.New("All fields are mandatory.")
  16. }
  17. return nil
  18. }
  19. func NewAuthForm(r *http.Request) *AuthForm {
  20. return &AuthForm{
  21. Username: r.FormValue("username"),
  22. Password: r.FormValue("password"),
  23. }
  24. }