-
Notifications
You must be signed in to change notification settings - Fork 6
/
models.go
47 lines (37 loc) · 1002 Bytes
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package users
import (
"errors"
"github.com/machinable/machinable/auth"
)
type updatePasswordBody struct {
OldPW string `json:"old_password"`
NewPW string `json:"new_password"`
}
// Validate checks that the new user has a username and password.
func (u *updatePasswordBody) Validate() error {
if u.OldPW == "" {
return errors.New("invalid current password")
}
if u.NewPW == "" {
return errors.New("invalid new password")
}
return nil
}
type newUserBody struct {
Email string `json:"email"`
Password string `json:"password"`
ReCaptcha string `json:"recaptcha"`
}
// Validate checks that the new user has a username and password.
func (u *newUserBody) Validate(reCaptchaSecret string) error {
if u.Email == "" || u.Password == "" {
return errors.New("invalid email or password")
}
if u.ReCaptcha == "" {
return errors.New("recaptcha must be submitted")
}
if err := auth.RecaptchaSiteVerify(u.ReCaptcha, reCaptchaSecret); err != nil {
return err
}
return nil
}