-
Notifications
You must be signed in to change notification settings - Fork 163
/
user.go
54 lines (43 loc) · 1.2 KB
/
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
46
47
48
49
50
51
52
53
54
package gorsk
import (
"time"
)
// User represents user domain model
type User struct {
Base
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username"`
Password string `json:"-"`
Email string `json:"email"`
Mobile string `json:"mobile,omitempty"`
Phone string `json:"phone,omitempty"`
Address string `json:"address,omitempty"`
Active bool `json:"active"`
LastLogin time.Time `json:"last_login,omitempty"`
LastPasswordChange time.Time `json:"last_password_change,omitempty"`
Token string `json:"-"`
Role *Role `json:"role,omitempty"`
RoleID AccessRole `json:"-"`
CompanyID int `json:"company_id"`
LocationID int `json:"location_id"`
}
// AuthUser represents data stored in JWT token for user
type AuthUser struct {
ID int
CompanyID int
LocationID int
Username string
Email string
Role AccessRole
}
// ChangePassword updates user's password related fields
func (u *User) ChangePassword(hash string) {
u.Password = hash
u.LastPasswordChange = time.Now()
}
// UpdateLastLogin updates last login field
func (u *User) UpdateLastLogin(token string) {
u.Token = token
u.LastLogin = time.Now()
}