function _ldapauth_save_user in LDAP integration 5.2
Same name and namespace in other branches
- 5 ldapauth.module \_ldapauth_save_user()
1 call to _ldapauth_save_user()
- _ldapauth_user_authenticate in ./ldapauth.module
File
- ./ldapauth.module, line 859
Code
function _ldapauth_save_user($login_string, $pass) {
global $user, $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_login_process', LDAP_FIRST_LDAP) == LDAP_FIRST_LDAP) {
$pass = user_password(20);
}
if (key_exists($ldap
->getOption('mail_attr') ? $ldap
->getOption('mail_attr') : LDAP_DEFAULT_MAIL_ATTRIBUTE, $ldap_user)) {
$mail = $ldap_user[$ldap
->getOption('mail_attr')][0];
}
else {
$mail = "";
}
$init = $dn;
$userinfo = array(
'name' => $login_string,
'pass' => $pass,
'mail' => $mail,
'init' => $init,
'status' => 1,
'authname_ldapauth' => $login_string,
'roles' => array(
DRUPAL_AUTHENTICATED_RID,
),
'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->name}"), WATCHDOG_ERROR);
module_invoke_all('user', 'logout', NULL, $user);
}
else {
$user = $account;
}
}
$config_name = $ldap
->getOption('name');
user_save($user, array(
'ldap_config' => $config_name,
));
$_SESSION['ldap_login']['dn'] = $dn;
$_SESSION['ldap_login']['pass'] = $pass;
return $user;
}