mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
feat: check application existence in object.AddUser() (#3686)
This commit is contained in:
parent
18bb445e71
commit
952538916d
@ -27,10 +27,10 @@ type LdapResp struct {
|
|||||||
ExistUuids []string `json:"existUuids"`
|
ExistUuids []string `json:"existUuids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//type LdapRespGroup struct {
|
// type LdapRespGroup struct {
|
||||||
// GroupId string
|
// GroupId string
|
||||||
// GroupName string
|
// GroupName string
|
||||||
//}
|
// }
|
||||||
|
|
||||||
type LdapSyncResp struct {
|
type LdapSyncResp struct {
|
||||||
Exist []object.LdapUser `json:"exist"`
|
Exist []object.LdapUser `json:"exist"`
|
||||||
@ -61,18 +61,18 @@ func (c *ApiController) GetLdapUsers() {
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
//groupsMap, err := conn.GetLdapGroups(ldapServer.BaseDn)
|
// groupsMap, err := conn.GetLdapGroups(ldapServer.BaseDn)
|
||||||
//if err != nil {
|
// if err != nil {
|
||||||
// c.ResponseError(err.Error())
|
// c.ResponseError(err.Error())
|
||||||
// return
|
// return
|
||||||
//}
|
// }
|
||||||
|
|
||||||
//for _, group := range groupsMap {
|
// for _, group := range groupsMap {
|
||||||
// resp.Groups = append(resp.Groups, LdapRespGroup{
|
// resp.Groups = append(resp.Groups, LdapRespGroup{
|
||||||
// GroupId: group.GidNumber,
|
// GroupId: group.GidNumber,
|
||||||
// GroupName: group.Cn,
|
// GroupName: group.Cn,
|
||||||
// })
|
// })
|
||||||
//}
|
// }
|
||||||
|
|
||||||
users, err := conn.GetLdapUsers(ldapServer)
|
users, err := conn.GetLdapUsers(ldapServer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -269,7 +269,11 @@ func (c *ApiController) SyncLdapUsers() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exist, failed, _ := object.SyncLdapUsers(owner, users, ldapId)
|
exist, failed, err := object.SyncLdapUsers(owner, users, ldapId)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.ResponseOk(&LdapSyncResp{
|
c.ResponseOk(&LdapSyncResp{
|
||||||
Exist: exist,
|
Exist: exist,
|
||||||
|
@ -106,6 +106,12 @@ func (l *LdapAutoSynchronizer) syncRoutine(ldap *Ldap, stopChan chan struct{}) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
existed, failed, err := SyncLdapUsers(ldap.Owner, AutoAdjustLdapUser(users), ldap.Id)
|
existed, failed, err := SyncLdapUsers(ldap.Owner, AutoAdjustLdapUser(users), ldap.Id)
|
||||||
|
if err != nil {
|
||||||
|
conn.Close()
|
||||||
|
logs.Warning(fmt.Sprintf("autoSync failed for %s, error %s", ldap.Id, err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if len(failed) != 0 {
|
if len(failed) != 0 {
|
||||||
logs.Warning(fmt.Sprintf("ldap autosync,%d new users,but %d user failed during :", len(users)-len(existed)-len(failed), len(failed)), failed)
|
logs.Warning(fmt.Sprintf("ldap autosync,%d new users,but %d user failed during :", len(users)-len(existed)-len(failed), len(failed)), failed)
|
||||||
logs.Warning(err.Error())
|
logs.Warning(err.Error())
|
||||||
|
@ -834,6 +834,16 @@ func AddUser(user *User) (bool, error) {
|
|||||||
return false, fmt.Errorf("the organization: %s is not found", user.Owner)
|
return false, fmt.Errorf("the organization: %s is not found", user.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.Owner != "built-in" {
|
||||||
|
applicationCount, err := GetOrganizationApplicationCount(organization.Owner, organization.Name, "", "")
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if applicationCount == 0 {
|
||||||
|
return false, fmt.Errorf("The organization: %s should have one application at least", organization.Owner)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if organization.DefaultPassword != "" && user.Password == "123" {
|
if organization.DefaultPassword != "" && user.Password == "123" {
|
||||||
user.Password = organization.DefaultPassword
|
user.Password = organization.DefaultPassword
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user