mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
Add Properties to user.
This commit is contained in:
@ -198,14 +198,26 @@ func (c *ApiController) Login() {
|
|||||||
user := object.GetUser(userId)
|
user := object.GetUser(userId)
|
||||||
|
|
||||||
// sync info from 3rd-party if possible
|
// sync info from 3rd-party if possible
|
||||||
if user.DisplayName == "" && userInfo.Username != "" {
|
if userInfo.Username != "" {
|
||||||
object.SetUserField(user, "display_name", userInfo.Username)
|
propertyName := fmt.Sprintf("oauth_%s_username", provider.Type)
|
||||||
|
object.SetUserProperty(user, propertyName, userInfo.Username)
|
||||||
|
if user.DisplayName == "" {
|
||||||
|
object.SetUserField(user, "display_name", userInfo.Username)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if user.Avatar == "" && userInfo.AvatarUrl != "" {
|
if userInfo.AvatarUrl != "" {
|
||||||
object.SetUserField(user, "avatar", userInfo.AvatarUrl)
|
propertyName := fmt.Sprintf("oauth_%s_avatarUrl", provider.Type)
|
||||||
|
object.SetUserProperty(user, propertyName, userInfo.AvatarUrl)
|
||||||
|
if user.Avatar == "" {
|
||||||
|
object.SetUserField(user, "avatar", userInfo.AvatarUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if user.Email == "" && userInfo.Email != "" {
|
if userInfo.Email != "" {
|
||||||
object.SetUserField(user, "email", userInfo.Email)
|
propertyName := fmt.Sprintf("oauth_%s_email", provider.Type)
|
||||||
|
object.SetUserProperty(user, propertyName, userInfo.Email)
|
||||||
|
if user.Email == "" {
|
||||||
|
object.SetUserField(user, "email", userInfo.Email)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isLinked := object.LinkUserAccount(user, provider.Type, userInfo.Username)
|
isLinked := object.LinkUserAccount(user, provider.Type, userInfo.Username)
|
||||||
|
@ -35,6 +35,7 @@ type User struct {
|
|||||||
Phone string `xorm:"varchar(100)" json:"phone"`
|
Phone string `xorm:"varchar(100)" json:"phone"`
|
||||||
Affiliation string `xorm:"varchar(100)" json:"affiliation"`
|
Affiliation string `xorm:"varchar(100)" json:"affiliation"`
|
||||||
Tag string `xorm:"varchar(100)" json:"tag"`
|
Tag string `xorm:"varchar(100)" json:"tag"`
|
||||||
|
Ranking int `json:"ranking"`
|
||||||
IsAdmin bool `json:"isAdmin"`
|
IsAdmin bool `json:"isAdmin"`
|
||||||
IsGlobalAdmin bool `json:"isGlobalAdmin"`
|
IsGlobalAdmin bool `json:"isGlobalAdmin"`
|
||||||
IsForbidden bool `json:"isForbidden"`
|
IsForbidden bool `json:"isForbidden"`
|
||||||
@ -45,6 +46,8 @@ type User struct {
|
|||||||
Google string `xorm:"varchar(100)" json:"google"`
|
Google string `xorm:"varchar(100)" json:"google"`
|
||||||
QQ string `xorm:"qq varchar(100)" json:"qq"`
|
QQ string `xorm:"qq varchar(100)" json:"qq"`
|
||||||
WeChat string `xorm:"wechat varchar(100)" json:"wechat"`
|
WeChat string `xorm:"wechat varchar(100)" json:"wechat"`
|
||||||
|
|
||||||
|
Properties map[string]string `json:"properties"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGlobalUsers() []*User {
|
func GetGlobalUsers() []*User {
|
||||||
|
@ -92,6 +92,21 @@ func GetUserField(user *User, field string) string {
|
|||||||
return f.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 {
|
func calculateHash(user *User) string {
|
||||||
s := strings.Join([]string{user.Id, user.Password, user.DisplayName, user.Avatar, user.Phone}, "|")
|
s := strings.Join([]string{user.Id, user.Password, user.DisplayName, user.Avatar, user.Phone}, "|")
|
||||||
return util.GetMd5Hash(s)
|
return util.GetMd5Hash(s)
|
||||||
|
@ -44,7 +44,7 @@ class UserListPage extends React.Component {
|
|||||||
|
|
||||||
newUser() {
|
newUser() {
|
||||||
return {
|
return {
|
||||||
owner: "admin", // this.props.account.username,
|
owner: "built-in", // this.props.account.username,
|
||||||
name: `user_${this.state.users.length}`,
|
name: `user_${this.state.users.length}`,
|
||||||
createdTime: moment().format(),
|
createdTime: moment().format(),
|
||||||
type: "normal-user",
|
type: "normal-user",
|
||||||
@ -58,6 +58,7 @@ class UserListPage extends React.Component {
|
|||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
isGlobalAdmin: false,
|
isGlobalAdmin: false,
|
||||||
IsForbidden: false,
|
IsForbidden: false,
|
||||||
|
properties: {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,18 +68,22 @@ class AuthCallback extends React.Component {
|
|||||||
|
|
||||||
UNSAFE_componentWillMount() {
|
UNSAFE_componentWillMount() {
|
||||||
const params = new URLSearchParams(this.props.location.search);
|
const params = new URLSearchParams(this.props.location.search);
|
||||||
|
const code = params.get("code");
|
||||||
|
|
||||||
const innerParams = this.getInnerParams();
|
const innerParams = this.getInnerParams();
|
||||||
const applicationName = innerParams.get("application");
|
const applicationName = innerParams.get("application");
|
||||||
const providerName = innerParams.get("provider");
|
const providerName = innerParams.get("provider");
|
||||||
const method = innerParams.get("method");
|
const method = innerParams.get("method");
|
||||||
|
|
||||||
let redirectUri = `${window.location.origin}/callback`;
|
let redirectUri = `${window.location.origin}/callback`;
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
type: this.getResponseType(),
|
type: this.getResponseType(),
|
||||||
application: applicationName,
|
application: applicationName,
|
||||||
provider: providerName,
|
provider: providerName,
|
||||||
code: params.get("code"),
|
code: code,
|
||||||
// state: innerParams.get("state"),
|
// state: innerParams.get("state"),
|
||||||
state: innerParams.get("application"),
|
state: applicationName,
|
||||||
redirectUri: redirectUri,
|
redirectUri: redirectUri,
|
||||||
method: method,
|
method: method,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user