Avoid linking the same account twice.

This commit is contained in:
Yang Luo 2021-06-18 23:25:24 +08:00
parent 01d5f3b776
commit 6dc3fd0f45
2 changed files with 15 additions and 0 deletions

View File

@ -304,6 +304,17 @@ func (c *ApiController) Login() {
return
}
oldUser := object.GetUserByField(application.Organization, provider.Type, userInfo.Id)
if oldUser == nil {
oldUser = object.GetUserByField(application.Organization, provider.Type, userInfo.Username)
}
if oldUser != nil {
resp = &Response{Status: "error", Msg: fmt.Sprintf("The account for provider: %s and username: %s (%s) is already linked to another account", provider.Type, userInfo.Username, userInfo.DisplayName)}
c.Data["json"] = resp
c.ServeJSON()
return
}
user := object.GetUser(userId)
// sync info from 3rd-party if possible

View File

@ -24,6 +24,10 @@ import (
)
func GetUserByField(organizationName string, field string, value string) *User {
if field == "" || value == "" {
return nil
}
user := User{Owner: organizationName}
existed, err := adapter.Engine.Where(fmt.Sprintf("%s=?", field), value).Get(&user)
if err != nil {