function _ldapauth_save_user in LDAP integration 5
Same name and namespace in other branches
- 5.2 ldapauth.module \_ldapauth_save_user()
1 call to _ldapauth_save_user()
- _ldapauth_user_authenticate in ./ldapauth.module
File
- ./ldapauth.module, line 951
Code
function _ldapauth_save_user($login_string, $pass) {
global $user, $ldapauth_ldap;
$account = user_load(array(
'name' => $login_string,
));
$ldap_user = _ldapauth_user_lookup($login_string);
if ($ldap_user) {
$dn = $ldap_user['dn'];
}
if (!isset($account->uid)) {
if (variable_get('ldap_forget_passwords', true)) {
$pass = user_password(20);
}
if (key_exists($ldapauth_ldap
->getOption('mail_attr') ? $ldapauth_ldap
->getOption('mail_attr') : LDAP_DEFAULT_MAIL_ATTRIBUTE, $ldap_user)) {
$mail = $ldap_user[$ldapauth_ldap
->getOption('mail_attr')][0];
}
else {
$mail = "";
}
$init = $mail;
$userinfo = array(
'name' => $login_string,
'pass' => $pass,
'mail' => $mail,
'init' => $init,
'status' => 1,
'authname_ldapauth' => $login_string,
'ldap_authentified' => TRUE,
'ldap_dn' => $dn,
);
$user = user_save('', $userinfo);
watchdog('user', t('New external user - ldapauth: %user using module %module.', array(
'%user' => theme('placeholder', $login_string),
'%module' => theme('placeholder', 'ldapauth'),
)), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $user->uid . '/edit'));
}
else {
if (!$account->ldap_authentified) {
drupal_set_message(t('Another user already exists in this system with the same login name. You should contact the system\'s administrator in order to solve this conflict.'), 'error');
watchdog('user', t('LDAP user with DN %dn has a naming conflict with non-LDAP user %account', array(
'%dn' => theme('placeholder', $dn),
'%account' => theme('placeholder', $account->name),
)), WATCHDOG_ERROR);
module_invoke_all('user', 'logout', NULL, $user);
}
else {
$user = $account;
}
}
if (key_exists($ldapauth_ldap
->getOption('mail_attr') ? $ldapauth_ldap
->getOption('mail_attr') : LDAP_DEFAULT_MAIL_ATTRIBUTE, $ldap_user)) {
$mail = $ldap_user[$ldapauth_ldap
->getOption('mail_attr')][0];
}
$config_name = $ldapauth_ldap
->getOption('name');
$userinfo = array(
'mail' => $mail,
'ldap_dn' => $dn,
'ldap_config' => $config_name,
);
$user = user_save($user, $userinfo);
$_SESSION['ldap_login']['dn'] = $dn;
$_SESSION['ldap_login']['pass'] = $pass;
return $user;
}