forked from revel/revel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
45 lines (37 loc) · 773 Bytes
/
user.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
package models
import (
"fmt"
"github.com/robfig/revel"
"regexp"
)
type User struct {
UserId int
Name string
Username, Password string
HashedPassword []byte
}
func (u *User) String() string {
return fmt.Sprintf("User(%s)", u.Username)
}
var userRegex = regexp.MustCompile("^\\w*$")
func (user *User) Validate(v *rev.Validation) {
v.Check(user.Username,
rev.Required{},
rev.MaxSize{15},
rev.MinSize{4},
rev.Match{userRegex},
)
ValidatePassword(v, user.Password).
Key("user.Password")
v.Check(user.Name,
rev.Required{},
rev.MaxSize{100},
)
}
func ValidatePassword(v *rev.Validation, password string) *rev.ValidationResult {
return v.Check(password,
rev.Required{},
rev.MaxSize{15},
rev.MinSize{5},
)
}