check for existing email address

This commit is contained in:
Roland Gruber 2018-05-22 19:55:49 +02:00
parent 6dfc06931a
commit 133d554916
3 changed files with 69 additions and 4 deletions

View File

@ -522,12 +522,23 @@ function buildUploadAccounts($type, $data, $ids, $selectedModules, htmlResponsiv
foreach ($data as $i => $dataRow) { foreach ($data as $i => $dataRow) {
$partialAccounts[$i]['objectClass'] = array(); $partialAccounts[$i]['objectClass'] = array();
} }
$stopUpload = false;
for ($i = 0; $i < sizeof($ordered); $i++) { for ($i = 0; $i < sizeof($ordered); $i++) {
$module = new $ordered[$i]($type->getScope()); $module = new $ordered[$i]($type->getScope());
$errors = $module->build_uploadAccounts($data, $ids, $partialAccounts, $selectedModules, $type); $moduleErrors = $module->build_uploadAccounts($data, $ids, $partialAccounts, $selectedModules, $type);
if (sizeof($errors) > 0) { if (sizeof($moduleErrors) > 0) {
array_unshift($errors, array("INFO", _("Displayed account numbers start at \"0\". Add 2 to get the row in your spreadsheet."), "")); $errors = array_merge($errors, $moduleErrors);
$errors[] = array("ERROR", _("Upload was stopped after errors in %s module!"), "", array($module->get_alias())); foreach ($moduleErrors as $error) {
if ($error[0] == 'ERROR') {
array_unshift($errors, array("INFO", _("Displayed account numbers start at \"0\". Add 2 to get the row in your spreadsheet."), ""));
$errors[] = array("ERROR", _("Upload was stopped after errors in %s module!"), "", array($module->get_alias()));
// skip other modules if error was found
$stopUpload = true;
break;
}
}
}
if ($stopUpload) {
break; break;
} }
} }
@ -537,6 +548,8 @@ function buildUploadAccounts($type, $data, $ids, $selectedModules, htmlResponsiv
$values = empty($errors[$i][3]) ? null : $errors[$i][3]; $values = empty($errors[$i][3]) ? null : $errors[$i][3];
$container->add(new htmlStatusMessage($errors[$i][0], $errors[$i][1], $text, $values), 12); $container->add(new htmlStatusMessage($errors[$i][0], $errors[$i][1], $text, $values), 12);
} }
}
if ($stopUpload) {
return false; return false;
} }
return $partialAccounts; return $partialAccounts;

View File

@ -79,6 +79,7 @@ class inetOrgPerson extends baseModule implements passwordService {
$this->messages['pager'][1] = array('ERROR', _('Account %s:') . ' inetOrgPerson_pager', _('Please enter a valid telephone number!')); $this->messages['pager'][1] = array('ERROR', _('Account %s:') . ' inetOrgPerson_pager', _('Please enter a valid telephone number!'));
$this->messages['mail'][0] = array('ERROR', _('Email address'), _('Please enter a valid email address!')); $this->messages['mail'][0] = array('ERROR', _('Email address'), _('Please enter a valid email address!'));
$this->messages['mail'][1] = array('WARN', _('Email address'), _('Email "%s" already in use.')); $this->messages['mail'][1] = array('WARN', _('Email address'), _('Email "%s" already in use.'));
$this->messages['mail'][2] = array('WARN', _('Account %s:') . ' inetOrgPerson_email', _('Email "%s" already in use.'));
$this->messages['email'][1] = array('ERROR', _('Account %s:') . ' inetOrgPerson_email', _('Please enter a valid email address!')); $this->messages['email'][1] = array('ERROR', _('Account %s:') . ' inetOrgPerson_email', _('Please enter a valid email address!'));
$this->messages['street'][0] = array('ERROR', _('Street'), _('Please enter a valid street name!')); $this->messages['street'][0] = array('ERROR', _('Street'), _('Please enter a valid street name!'));
$this->messages['street'][1] = array('ERROR', _('Account %s:') . ' inetOrgPerson_street', _('Please enter a valid street name!')); $this->messages['street'][1] = array('ERROR', _('Account %s:') . ' inetOrgPerson_street', _('Please enter a valid street name!'));
@ -2218,6 +2219,10 @@ class inetOrgPerson extends baseModule implements passwordService {
for ($e = 0; $e < sizeof($existingUsers); $e++) { for ($e = 0; $e < sizeof($existingUsers); $e++) {
$existingUsers[$e] = $existingUsers[$e]['uid'][0]; $existingUsers[$e] = $existingUsers[$e]['uid'][0];
} }
$existingMails = searchLDAPByAttribute('mail', '*', 'inetOrgPerson', array('mail'), array('user'));
for ($e = 0; $e < sizeof($existingMails); $e++) {
$existingMails[$e] = $existingMails[$e]['mail'][0];
}
for ($i = 0; $i < sizeof($rawAccounts); $i++) { for ($i = 0; $i < sizeof($rawAccounts); $i++) {
if (!in_array("inetOrgPerson", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "inetOrgPerson"; if (!in_array("inetOrgPerson", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "inetOrgPerson";
// last name // last name
@ -2340,6 +2345,11 @@ class inetOrgPerson extends baseModule implements passwordService {
$errors[] = $errMsg; $errors[] = $errMsg;
break; break;
} }
elseif (in_array($mailList[$x], $existingMails)) {
$errMsg = $this->messages['mail'][2];
array_push($errMsg, array($i, $mailList[$x]));
$errors[] = $errMsg;
}
} }
} }
if (isLAMProVersion() && isset($ids['inetOrgPerson_sendPasswordMail']) && ($rawAccounts[$i][$ids['inetOrgPerson_sendPasswordMail']] != "")) { if (isLAMProVersion() && isset($ids['inetOrgPerson_sendPasswordMail']) && ($rawAccounts[$i][$ids['inetOrgPerson_sendPasswordMail']] != "")) {

View File

@ -977,8 +977,12 @@ class windowsUser extends baseModule implements passwordService {
$this->messages['postalCode'][1] = array('ERROR', _('Account %s:') . ' windowsUser_postalCode', _('Please enter a valid postal code!')); $this->messages['postalCode'][1] = array('ERROR', _('Account %s:') . ' windowsUser_postalCode', _('Please enter a valid postal code!'));
$this->messages['mail'][0] = array('ERROR', _('Email address'), _('Please enter a valid email address!')); $this->messages['mail'][0] = array('ERROR', _('Email address'), _('Please enter a valid email address!'));
$this->messages['mail'][1] = array('ERROR', _('Account %s:') . ' windowsUser_mail', _('Please enter a valid email address!')); $this->messages['mail'][1] = array('ERROR', _('Account %s:') . ' windowsUser_mail', _('Please enter a valid email address!'));
$this->messages['mail'][2] = array('WARN', _('Email address'), _('Email "%s" already in use.'));
$this->messages['mail'][3] = array('WARN', _('Account %s:') . ' windowsUser_mail', _('Email "%s" already in use.'));
$this->messages['otherMailbox'][0] = array('ERROR', _('Email alias'), _('Email alias is invalid!')); $this->messages['otherMailbox'][0] = array('ERROR', _('Email alias'), _('Email alias is invalid!'));
$this->messages['otherMailbox'][1] = array('ERROR', _('Account %s:') . ' windowsUser_otherMailbox', _('Email alias is invalid!')); $this->messages['otherMailbox'][1] = array('ERROR', _('Account %s:') . ' windowsUser_otherMailbox', _('Email alias is invalid!'));
$this->messages['otherMailbox'][2] = array('WARN', _('Email alias'), _('Email alias "%s" already in use.'));
$this->messages['otherMailbox'][3] = array('WARN', _('Account %s:') . ' windowsUser_otherMailbox', _('Email alias "%s" already in use.'));
$this->messages['profilePath'][0] = array('ERROR', _('Profile path'), _('Profile path is invalid!')); $this->messages['profilePath'][0] = array('ERROR', _('Profile path'), _('Profile path is invalid!'));
$this->messages['profilePath'][1] = array('ERROR', _('Account %s:') . ' windowsUser_profilePath', _('Profile path is invalid!')); $this->messages['profilePath'][1] = array('ERROR', _('Account %s:') . ' windowsUser_profilePath', _('Profile path is invalid!'));
$this->messages['scriptPath'][0] = array('ERROR', _('Logon script'), _('Logon script is invalid!')); $this->messages['scriptPath'][0] = array('ERROR', _('Logon script'), _('Logon script is invalid!'));
@ -1383,8 +1387,26 @@ class windowsUser extends baseModule implements passwordService {
if (!empty($this->attributes['mail'][0]) && !get_preg($this->attributes['mail'][0], 'email')) { if (!empty($this->attributes['mail'][0]) && !get_preg($this->attributes['mail'][0], 'email')) {
$return[] = $this->messages['mail'][0]; $return[] = $this->messages['mail'][0];
} }
elseif (!empty($this->attributes['mail'][0]) && $this->getAccountContainer()->isNewAccount) {
$existingMailAccounts = searchLDAPByAttribute('mail', $this->attributes['mail'][0], 'user', array('mail'), array('user'));
if (!empty($existingMailAccounts)) {
$msg = $this->messages['mail'][2];
$msg[] = array($this->attributes['mail'][0]);
$return[] = $msg;
}
}
// email aliases // email aliases
$this->processMultiValueInputTextField('otherMailbox', $return, 'email'); $this->processMultiValueInputTextField('otherMailbox', $return, 'email');
if (!empty($this->attributes['otherMailbox'][0]) && $this->getAccountContainer()->isNewAccount) {
foreach ($this->attributes['otherMailbox'] as $otherMailbox) {
$existingMailAccounts = searchLDAPByAttribute('otherMailbox', $otherMailbox, 'user', array('otherMailbox'), array('user'));
if (!empty($existingMailAccounts)) {
$msg = $this->messages['otherMailbox'][2];
$msg[] = array($otherMailbox);
$return[] = $msg;
}
}
}
// other telephones // other telephones
$this->processMultiValueInputTextField('otherTelephone', $return, 'telephone'); $this->processMultiValueInputTextField('otherTelephone', $return, 'telephone');
// fax number // fax number
@ -1991,6 +2013,16 @@ class windowsUser extends baseModule implements passwordService {
$groupMap[extractRDNValue($dn)] = $dn; $groupMap[extractRDNValue($dn)] = $dn;
} }
$existingUsers = $this->getUserNames(); $existingUsers = $this->getUserNames();
$existingMailAccounts = searchLDAPByAttribute(null, null, 'user', array('mail', 'otherMailbox'), array('user'));
$existingMails = array();
foreach ($existingMailAccounts as $existingMailAccount) {
if (!empty($existingMailAccount['mail'][0])) {
$existingMails[] = $existingMailAccount['mail'][0];
}
if (!empty($existingMailAccount['othermailbox'][0])) {
$existingMails = array_merge($existingMails, $existingMailAccount['othermailbox']);
}
}
$booleanOptions = array(_('yes') => true, _('no') => false); $booleanOptions = array(_('yes') => true, _('no') => false);
for ($i = 0; $i < sizeof($rawAccounts); $i++) { for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class // add object class
@ -2116,6 +2148,11 @@ class windowsUser extends baseModule implements passwordService {
if ($rawAccounts[$i][$ids['windowsUser_mail']] != "") { if ($rawAccounts[$i][$ids['windowsUser_mail']] != "") {
if (get_preg($rawAccounts[$i][$ids['windowsUser_mail']], 'email')) { if (get_preg($rawAccounts[$i][$ids['windowsUser_mail']], 'email')) {
$partialAccounts[$i]['mail'] = $rawAccounts[$i][$ids['windowsUser_mail']]; $partialAccounts[$i]['mail'] = $rawAccounts[$i][$ids['windowsUser_mail']];
if (in_array_ignore_case($partialAccounts[$i]['mail'], $existingMails)) {
$errMsg = $this->messages['mail'][3];
array_push($errMsg, array($i, $partialAccounts[$i]['mail']));
$errors[] = $errMsg;
}
} }
else { else {
$errMsg = $this->messages['mail'][1]; $errMsg = $this->messages['mail'][1];
@ -2134,6 +2171,11 @@ class windowsUser extends baseModule implements passwordService {
$errors[] = $errMsg; $errors[] = $errMsg;
break; break;
} }
if (in_array_ignore_case($valueList[$x], $existingMails)) {
$errMsg = $this->messages['otherMailbox'][3];
array_push($errMsg, array($i, $valueList[$x]));
$errors[] = $errMsg;
}
} }
} }
// telephone // telephone