mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Sync info from 3rd-party if possible.
This commit is contained in:
parent
6002395d12
commit
c317d601a5
@ -196,6 +196,18 @@ func (c *ApiController) Login() {
|
||||
}
|
||||
|
||||
user := object.GetUser(userId)
|
||||
|
||||
// sync info from 3rd-party if possible
|
||||
if user.DisplayName == "" && userInfo.Username != "" {
|
||||
object.SetUserField(user, "displayName", userInfo.Username)
|
||||
}
|
||||
if user.Avatar == "" && userInfo.AvatarUrl != "" {
|
||||
object.SetUserField(user, "avatar", userInfo.AvatarUrl)
|
||||
}
|
||||
if user.Email == "" && userInfo.Email != "" {
|
||||
object.SetUserField(user, "email", userInfo.Email)
|
||||
}
|
||||
|
||||
isLinked := object.LinkUserAccount(user, provider.Type, userInfo.Username)
|
||||
if isLinked {
|
||||
resp = &Response{Status: "ok", Msg: "", Data: isLinked}
|
||||
|
@ -142,7 +142,7 @@ func GetUserByField(organizationName string, field string, value string) *User {
|
||||
}
|
||||
}
|
||||
|
||||
func LinkUserAccount(user *User, field string, value string) bool {
|
||||
func SetUserField(user *User, field string, value string) bool {
|
||||
affected, err := adapter.engine.Table(user).ID(core.PK{user.Owner, user.Name}).Update(map[string]interface{}{field: value})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -151,6 +151,10 @@ func LinkUserAccount(user *User, field string, value string) bool {
|
||||
return affected != 0
|
||||
}
|
||||
|
||||
func LinkUserAccount(user *User, field string, value string) bool {
|
||||
return SetUserField(user, field, value)
|
||||
}
|
||||
|
||||
func GetUserField(user *User, field string) string {
|
||||
// https://socketloop.com/tutorials/golang-how-to-get-struct-field-and-value-by-name
|
||||
u := reflect.ValueOf(user)
|
||||
|
Loading…
x
Reference in New Issue
Block a user