-
Notifications
You must be signed in to change notification settings - Fork 96
/
user.go
126 lines (104 loc) · 3.37 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package db
import (
"database/sql/driver"
"encoding/json"
"golang.org/x/oauth2"
)
// swagger:model user
type User struct {
Uid int `gorm:"not null;primary_key;AUTO_INCREMENT"json:"uid"`
Oaid int `gorm:"not null;comment:'oa uid'"json:"id"`
Username string `gorm:"not null;comment:'用户名'"json:"username"`
Nickname string `gorm:"not null;comment:'昵称'"json:"nickname"`
Secret string `gorm:"not null;comment:'秘钥'"json:"secret"`
Email string `gorm:"not null;comment:'email'"json:"email"`
Avatar string `gorm:"not null;comment:'avatart'"json:"avatar"`
WebUrl string `gorm:"not null;comment:'注释'"json:"webUrl"`
State string `gorm:"not null;comment:'注释'"json:"state"`
Hash string `gorm:"not null;comment:'注释'"json:"hash"`
CreateTime int64 `gorm:"not null;comment:'注释'"json:"createTime"`
UpdateTime int64 `gorm:"not null;comment:'注释'"json:"updateTime"`
authenticated bool `form:"-" db:"-" json:"-"`
Oauth string `gorm:"not null;"json:"oauth"` // 来源
OauthId string `gorm:"not null;"json:"oauthId"` // 来源id
Password string `gorm:"not null;comment:'注释'"json:"password"`
// open source user data
CurrentAuthority string `json:"currentAuthority"`
Access string `json:"access"`
OauthToken OAuthToken `gorm:"type:json;comment:'OAuth Token 信息'" json:"-"`
Groups []CasbinPolicyGroup `gorm:"foreignKey:Uid;association_foreignkey:Uid" json:"-"`
}
type UserList []User
type OAuthToken struct {
*oauth2.Token
}
func (u *User) TransformUserInfo() UserInfo {
return UserInfo{
Oaid: u.Oaid,
Uid: u.Uid,
Username: u.Username,
Nickname: u.Nickname,
Secret: u.Secret,
Email: u.Email,
Avatar: u.Avatar,
WebUrl: u.WebUrl,
State: u.State,
Hash: u.Hash,
CreateTime: u.CreateTime,
UpdateTime: u.UpdateTime,
Authenticated: u.authenticated,
Access: u.Access,
}
}
func (u *User) IsLogin() bool {
if u.Uid > 0 {
return true
}
return false
}
// UserInfo ...
type UserInfo struct {
// the id for this user.
//
// required: true
// oa uid
Oaid int `json:"oaid"`
// gitlab uid
Uid int `json:"uid"`
// Login is the username for this user.
//
// required: true
Username string `json:"username"`
Nickname string `json:"nickname"`
// AccessToken is the oauth2 token.
Token string `json:"token"`
// Secret is the oauth2 token secret.
Secret string `json:"secret"`
// Email is the email address for this user.
// required: true
Email string `json:"email"`
// the avatar url for this user.
Avatar string `json:"avatarUrl"`
WebUrl string `json:"webUrl"`
State string `json:"state"`
// Hash is a unique token used to sign tokens.
Hash string `json:"hash"`
// DEPRECATED Admin indicates the user is a system administrator.
CreateTime int64 `json:"create_time"`
UpdateTime int64 `json:"update_time"`
// GitlabUid is the id of gitlab user
Authenticated bool `form:"-" db:"-" json:"-"`
Access string `json:"access"`
}
// TableName 指定Menu结构体对应的表名
func (User) TableName() string {
return "user"
}
func (o OAuthToken) Value() (driver.Value, error) {
b, err := json.Marshal(o)
return string(b), err
}
// Scan ..
func (o *OAuthToken) Scan(input interface{}) error {
return json.Unmarshal(input.([]byte), o)
}