mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Add Properties to user.
This commit is contained in:
@ -35,6 +35,7 @@ type User struct {
|
||||
Phone string `xorm:"varchar(100)" json:"phone"`
|
||||
Affiliation string `xorm:"varchar(100)" json:"affiliation"`
|
||||
Tag string `xorm:"varchar(100)" json:"tag"`
|
||||
Ranking int `json:"ranking"`
|
||||
IsAdmin bool `json:"isAdmin"`
|
||||
IsGlobalAdmin bool `json:"isGlobalAdmin"`
|
||||
IsForbidden bool `json:"isForbidden"`
|
||||
@ -45,6 +46,8 @@ type User struct {
|
||||
Google string `xorm:"varchar(100)" json:"google"`
|
||||
QQ string `xorm:"qq varchar(100)" json:"qq"`
|
||||
WeChat string `xorm:"wechat varchar(100)" json:"wechat"`
|
||||
|
||||
Properties map[string]string `json:"properties"`
|
||||
}
|
||||
|
||||
func GetGlobalUsers() []*User {
|
||||
|
@ -92,6 +92,21 @@ func GetUserField(user *User, field string) string {
|
||||
return f.String()
|
||||
}
|
||||
|
||||
func SetUserProperty(user *User, field string, value string) bool {
|
||||
if value == "" {
|
||||
delete(user.Properties, field)
|
||||
} else {
|
||||
user.Properties[field] = value
|
||||
}
|
||||
|
||||
affected, err := adapter.Engine.ID(core.PK{user.Owner, user.Name}).Cols("properties").Update(user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return affected != 0
|
||||
}
|
||||
|
||||
func calculateHash(user *User) string {
|
||||
s := strings.Join([]string{user.Id, user.Password, user.DisplayName, user.Avatar, user.Phone}, "|")
|
||||
return util.GetMd5Hash(s)
|
||||
|
Reference in New Issue
Block a user