2
0

create_input.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package generated
  2. import (
  3. passwordvalidator "github.com/wagslane/go-password-validator"
  4. "net/mail"
  5. "strings"
  6. )
  7. func (input CustomerCreateInput) ValidatePassword(minPasswordEntropy float64) *CustomerUserError {
  8. var code CustomerErrorCode
  9. if strings.HasPrefix(input.Password, " ") || strings.HasSuffix(input.Password, " ") {
  10. code = CustomerErrorCodePasswordStartsOrEndsWithWhitespace
  11. return &CustomerUserError{
  12. Code: &code,
  13. Field: []string{"password"},
  14. Message: "password must not start or end with whitespaces",
  15. }
  16. }
  17. if err := passwordvalidator.Validate(input.Password, minPasswordEntropy); err != nil {
  18. code = CustomerErrorCodeBlank
  19. return &CustomerUserError{
  20. Code: &code,
  21. Field: []string{"password"},
  22. Message: err.Error(),
  23. }
  24. }
  25. return nil
  26. }
  27. func (input CustomerCreateInput) ValidateEmail() *CustomerUserError {
  28. addr, err := mail.ParseAddress(input.Email)
  29. if err != nil {
  30. code := CustomerErrorCodeInvalid
  31. return &CustomerUserError{
  32. Code: &code,
  33. Field: []string{"email"},
  34. Message: err.Error(),
  35. }
  36. }
  37. input.Email = addr.Address
  38. return nil
  39. }