function simple_ldap_user_profile_form_validate in Simple LDAP 7.2
1 string reference to 'simple_ldap_user_profile_form_validate'
- simple_ldap_user_form_alter in simple_ldap_user/
simple_ldap_user.module - Implements hook_form_alter().
File
- simple_ldap_user/
simple_ldap_user.module, line 562 - Main simple_ldap_user module file.
Code
function simple_ldap_user_profile_form_validate($form, &$form_state) {
$ldap_user_by_name = SimpleLdapUser::singleton($form_state['values']['name']);
$ldap_user_by_mail = SimpleLdapUser::singleton($form_state['values']['mail']);
$account = $form_state['user'];
$ldap_user = SimpleLdapUser::singleton($account->name);
// Pull all three DNs
$name_dn = $ldap_user_by_name->dn;
$mail_dn = $ldap_user_by_mail->dn;
$user_dn = $ldap_user->dn;
// Make sure he doesn't collide with an existing LDAP user
if (!$ldap_user->exists) {
if ($ldap_user_by_name->exists) {
form_set_error('name', t('Another user has that username.'));
}
if ($ldap_user_by_mail->exists) {
form_set_error('mail', t('Another user has that email address.'));
}
}
else {
if ($user_dn !== $name_dn && $ldap_user_by_name->exists) {
form_set_error('name', t('Another user has that username.'));
}
if ($user_dn !== $mail_dn && $ldap_user_by_mail->exists) {
form_set_error('mail', t('Another user has that email address.'));
}
}
}