-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
39 lines (32 loc) · 890 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
package SexModel
import (
"time"
"github.com/Plankiton/SexPistol/Cartridge"
)
type User struct {
SexDB.Model
Email string `json:"email,omitempty" gorm:"unique,default:null"`
Name string `json:"name,omitempty" gorm:"index"`
Born time.Time `json:"born_date,omitempty" gorm:"index"`
Genre string `json:"genre,omitempty" gorm:"default:'male'"`
PassHash string `json:"-"`
}
func (m User) TableName() string {
return "users"
}
func (model *User) CheckPass(s string) bool {
byteHash := []byte(model.PassHash)
err := SexDB.CheckPass(byteHash, s)
if err != nil {
return false
}
return true
}
func (model *User) SetPass(s string) (string, error) {
hash, err := SexDB.ToPassHash(s)
if err != nil {
return "", nil
}
model.PassHash = hash
return model.PassHash, nil
}