|
@@ -24,7 +24,20 @@ func (c *UserService) Add(body *models.LdapUser) (*models.LdapUser, error) {
|
|
|
return nil, err
|
|
|
}
|
|
|
body.Uid = server.Uid
|
|
|
- _, err = o.InsertOrUpdate(body)
|
|
|
+
|
|
|
+ exist := models.LdapUser{
|
|
|
+ Account: body.Account,
|
|
|
+ }
|
|
|
+ err = o.Read(&exist, "Account")
|
|
|
+ if err != nil && errors.Is(err, orm.ErrNoRows) {
|
|
|
+ _, err = o.Insert(&body)
|
|
|
+ } else if err != nil {
|
|
|
+ return nil, err
|
|
|
+ } else {
|
|
|
+ body.Id = exist.Id
|
|
|
+ _, err = o.Update(body)
|
|
|
+ }
|
|
|
+
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -151,13 +164,13 @@ func (c *UserService) SyncUsers(current *models.User, req *LDAPUserSyncReq) (int
|
|
|
}
|
|
|
for _, user := range users {
|
|
|
user.Uid = string(rune(current.Id))
|
|
|
- _, err := o.InsertOrUpdate(user, "DN")
|
|
|
+ _, err := InsertOrUpdate(o, user, "DN")
|
|
|
if err != nil {
|
|
|
logs.Error("save user fail: %v", err)
|
|
|
}
|
|
|
}
|
|
|
for _, organize := range organizeList {
|
|
|
- _, err = o.InsertOrUpdate(organize, "DN")
|
|
|
+ _, err = InsertOrUpdate(o, organize, "DN")
|
|
|
if err != nil {
|
|
|
logs.Error("save organize fail: %v", err)
|
|
|
}
|
|
@@ -182,7 +195,7 @@ func (c *UserService) Authentication(server *models.LdapServer, account string,
|
|
|
return nil, errors.New("您输入的账号或者密码错误!")
|
|
|
}
|
|
|
ldapUser = users[0]
|
|
|
- _, err = o.InsertOrUpdate(ldapUser, "DN")
|
|
|
+ _, err = InsertOrUpdate(o, ldapUser, "DN")
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|