function simplesamlphp_auth_user_insert in simpleSAMLphp Authentication 7.2
Same name and namespace in other branches
- 7.3 simplesamlphp_auth.module \simplesamlphp_auth_user_insert()
- 7 simplesamlphp_auth.module \simplesamlphp_auth_user_insert()
Implements hook_user_insert().
File
- ./
simplesamlphp_auth.module, line 368 - simpleSAMLphp authentication module for Drupal.
Code
function simplesamlphp_auth_user_insert(&$edit, $account, $category = NULL) {
global $_simplesamlphp_auth_as;
global $_simplesamlphp_auth_saml_attributes;
if (!_simplesamlphp_auth_isEnabled()) {
// Exit without initializing.
return;
}
if ($category == 'account') {
// If user registration has a valid session...
if ($_simplesamlphp_auth_as
->isAuthenticated()) {
// Get name from default attributes.
try {
_simplesaml_auth_debug(t('Registering user [%acctname]', array(
'%acctname' => $account->name,
)));
$account->name = _simplesamlphp_auth_get_default_name($account->uid);
} catch (Exception $e) {
drupal_set_message(t('Your user name was not provided by your identity provider (IDP).'), "error");
watchdog('simplesamlphp_auth', $e
->getMessage(), NULL, WATCHDOG_CRITICAL);
}
db_update('users')
->fields(array(
'name' => $account->name,
))
->condition('uid', $account->uid)
->execute();
_simplesaml_auth_debug(t('Updating username [%acctname]', array(
'%acctname' => $account->name,
)));
// Get mail from default attribute.
try {
$mail_address = _simplesamlphp_auth_get_mail();
} catch (Exception $e) {
drupal_set_message(t('Your e-mail address was not provided by your identity provider (IDP).'), "error");
watchdog('simplesamlphp_auth', $e
->getMessage(), NULL, WATCHDOG_CRITICAL);
}
if (!empty($mail_address)) {
db_update('users')
->fields(array(
'mail' => $mail_address,
))
->condition('uid', $account->uid)
->execute();
}
if (module_exists('rules')) {
rules_invoke_event('simplesamlphp_auth_rules_event_register', $account);
}
_simplesaml_auth_debug(t('Updating mail [%mailaddr]', array(
'%mailaddr' => $mail_address,
)));
}
}
}