-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
user.go
68 lines (59 loc) · 1.14 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
package uic
import (
con "github.com/open-falcon/falcon-plus/modules/api/config"
"github.com/spf13/viper"
)
type User struct {
ID int64 `json:"id" `
Name string `json:"name"`
Cnname string `json:"cnname"`
Passwd string `json:"-"`
Email string `json:"email"`
Phone string `json:"phone"`
IM string `json:"im" gorm:"column:im"`
QQ string `json:"qq" gorm:"column:qq"`
Role int `json:"role"`
}
func skipAccessControll() bool {
return !viper.GetBool("access_control")
}
func (this User) IsAdmin() bool {
if skipAccessControll() {
return true
}
if this.Role == 2 || this.Role == 1 {
return true
}
return false
}
func (this User) IsSuperAdmin() bool {
if skipAccessControll() {
return true
}
if this.Role == 2 {
return true
}
return false
}
func (this User) FindUser() (user User, err error) {
db := con.Con()
user = this
dt := db.Uic.Find(&user)
if dt.Error != nil {
err = dt.Error
return
}
return
}
type Session struct {
ID int64
Uid int64
Sig string
Expired int
}
func (this Session) TableName() string {
return "session"
}
func (this User) TableName() string {
return "user"
}