function shib_auth_save_mail in Shibboleth Authentication 7.4
Same name and namespace in other branches
- 6.4 shib_auth.module \shib_auth_save_mail()
Saves changes to user's email.
Unfortunately if we called user_save() on updating email, we would possibly lose profile fields, so we are forced to hack with the {users} table.
Parameters
object $account: User account to modify.
string $mail: New mail address.
Return value
object|false Modified user object or FALSE on error, just like user_save would do.
2 calls to shib_auth_save_mail()
- shib_auth_save_authmap in ./
shib_auth.module - Saves an entry into shib_authmap and also saves mail if changed.
- shib_login_authmap in ./
shib_auth.module - Login a user based on the shib_authmap information.
File
- ./
shib_auth.module, line 1416 - Drupal Shibboleth authentication module.
Code
function shib_auth_save_mail($account, $mail) {
// Basic parameter checks to avoid do anything fatal.
if (!is_object($account) || !$account->uid || $account->uid <= 1) {
return FALSE;
}
if (!valid_email_address($mail)) {
shib_auth_error('Email address is invalid');
return FALSE;
}
// If the mail hasn't changed, do not do anything.
if ($account->mail && $account->mail == $mail) {
return $account;
}
// We deliberately do not call user_module_invoke('update',..) here, because
// profile module seems to take it too seriously and wipes out profile fields.
// Cross fingers, do the update.
$success = db_update('users')
->fields(array(
'mail' => $mail,
))
->condition('uid', $account->uid, '=')
->execute();
if (!$success) {
// Failed for some reason?
shib_auth_error(t('Error saving mail'));
return FALSE;
}
// Refresh user object.
$account->mail = $mail;
// We can call things hooked on after_update.
$null = NULL;
user_module_invoke('after_update', $null, $account);
return $account;
}