mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
Add UpdateUserInternal().
This commit is contained in:
@ -263,6 +263,11 @@ func (c *ApiController) Login() {
|
||||
}
|
||||
object.AddUser(user)
|
||||
|
||||
// sync info from 3rd-party if possible
|
||||
object.SetUserOAuthProperties(user, provider.Type, userInfo)
|
||||
|
||||
object.LinkUserAccount(user, provider.Type, userInfo.Id)
|
||||
|
||||
resp = c.HandleLoggedIn(user, &form)
|
||||
} else if !application.EnableSignUp {
|
||||
resp = &Response{Status: "error", Msg: fmt.Sprintf("The account for provider: %s and username: %s does not exist and is not allowed to sign up as new account, please contact your IT support", provider.Type, userInfo.Username)}
|
||||
|
@ -124,6 +124,22 @@ func UpdateUser(id string, user *User) bool {
|
||||
return affected != 0
|
||||
}
|
||||
|
||||
func UpdateUserInternal(id string, user *User) bool {
|
||||
owner, name := util.GetOwnerAndNameFromId(id)
|
||||
if getUser(owner, name) == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
user.UpdateUserHash()
|
||||
|
||||
affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return affected != 0
|
||||
}
|
||||
|
||||
func UpdateUserForOriginal(user *User) bool {
|
||||
affected, err := adapter.Engine.ID(core.PK{user.Owner, user.Name}).Cols("display_name", "password", "phone", "avatar", "affiliation", "score", "is_forbidden", "hash", "pre_hash").Update(user)
|
||||
if err != nil {
|
||||
|
@ -113,30 +113,26 @@ func SetUserOAuthProperties(user *User, providerType string, userInfo *idp.UserI
|
||||
propertyName := fmt.Sprintf("oauth_%s_displayName", providerType)
|
||||
setUserProperty(user, propertyName, userInfo.DisplayName)
|
||||
if user.DisplayName == "" {
|
||||
SetUserField(user, "display_name", userInfo.DisplayName)
|
||||
user.DisplayName = userInfo.DisplayName
|
||||
}
|
||||
}
|
||||
if userInfo.Email != "" {
|
||||
propertyName := fmt.Sprintf("oauth_%s_email", providerType)
|
||||
setUserProperty(user, propertyName, userInfo.Email)
|
||||
if user.Email == "" {
|
||||
SetUserField(user, "email", userInfo.Email)
|
||||
user.Email = userInfo.Email
|
||||
}
|
||||
}
|
||||
if userInfo.AvatarUrl != "" {
|
||||
propertyName := fmt.Sprintf("oauth_%s_avatarUrl", providerType)
|
||||
setUserProperty(user, propertyName, userInfo.AvatarUrl)
|
||||
if user.Avatar == "" {
|
||||
SetUserField(user, "avatar", userInfo.AvatarUrl)
|
||||
user.Avatar = userInfo.AvatarUrl
|
||||
}
|
||||
}
|
||||
|
||||
affected, err := adapter.Engine.ID(core.PK{user.Owner, user.Name}).Cols("properties").Update(user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return affected != 0
|
||||
affected := UpdateUserInternal(user.GetId(), user)
|
||||
return affected
|
||||
}
|
||||
|
||||
func ClearUserOAuthProperties(user *User, providerType string) bool {
|
||||
|
Reference in New Issue
Block a user