forked from VaalaCat/frp-panel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
109 lines (90 loc) · 1.87 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package models
import (
"fmt"
"time"
"gorm.io/gorm"
)
type User struct {
*UserEntity
}
type UserInfo interface {
GetUserID() int
GetUserIDStr() string
GetUserName() string
GetEmail() string
GetHashedPassword() string
GetStatus() int
GetRole() string
GetToken() string
GetTenantID() int
GetSafeUserInfo() UserEntity
IsAdmin() bool
Valid() bool
}
var _ UserInfo = (*UserEntity)(nil)
type UserEntity struct {
UserID int `json:"user_id" gorm:"primaryKey"`
UserName string `json:"user_name" gorm:"uniqueIndex;not null"`
Password string `json:"password"`
Email string `json:"email" gorm:"uniqueIndex;not null"`
Status int `json:"status"`
Role string `json:"role"`
TenantID int `json:"tenant_id"`
Token string `json:"token"`
CreatedAt time.Time
UpdatedAt time.Time
Bandwidth int
UsedBandwidith int
DeletedAt gorm.DeletedAt `gorm:"index"`
}
func (u *UserEntity) GetUserID() int {
return u.UserID
}
func (u *UserEntity) GetUserIDStr() string {
return fmt.Sprint(u.UserID)
}
func (u *UserEntity) GetUserName() string {
return u.UserName
}
func (u *UserEntity) GetEmail() string {
return u.Email
}
func (u *UserEntity) GetHashedPassword() string {
return u.Password
}
func (u *UserEntity) GetStatus() int {
return u.Status
}
func (u *UserEntity) GetRole() string {
return u.Role
}
func (u *UserEntity) GetTenantID() int {
return u.TenantID
}
func (u *UserEntity) GetToken() string {
return u.Token
}
func (u *UserEntity) GetSafeUserInfo() UserEntity {
return UserEntity{
UserID: u.UserID,
UserName: u.UserName,
Email: u.Email,
Status: u.Status,
Role: u.Role,
}
}
func (u *UserEntity) Valid() bool {
if u == nil {
return false
}
if u.Status == STATUS_BANED {
return false
}
return true
}
func (u *UserEntity) IsAdmin() bool {
return u.Role == ROLE_ADMIN
}
func (u *User) TableName() string {
return "users"
}