You are here

function user_set_authmaps in Drupal 7

Same name and namespace in other branches
  1. 4 modules/user.module \user_set_authmaps()
  2. 5 modules/user/user.module \user_set_authmaps()
  3. 6 modules/user/user.module \user_set_authmaps()

Save mappings of which external authentication module(s) authenticated a user. Maps external usernames to user ids in the users table.

Parameters

$account: A user object.

$authmaps: An associative array with a compound key and the username as the value. The key is made up of 'authname_' plus the name of the external authentication module.

See also

user_external_login_register()

3 calls to user_set_authmaps()
openid_user_insert in modules/openid/openid.module
Implements hook_user_insert().
UserAuthmapAssignmentTestCase::testAuthmapAssignment in modules/user/user.test
Test authmap assignment and retrieval.
user_external_login_register in modules/user/user.module
Helper function for authentication modules. Either logs in or registers the current user, based on username. Either way, the global $user object is populated and login tasks are performed.

File

modules/user/user.module, line 2077
Enables the user registration and login system.

Code

function user_set_authmaps($account, $authmaps) {
  foreach ($authmaps as $key => $value) {
    $module = explode('_', $key, 2);
    if ($value) {
      db_merge('authmap')
        ->key(array(
        'uid' => $account->uid,
        'module' => $module[1],
      ))
        ->fields(array(
        'authname' => $value,
      ))
        ->execute();
    }
    else {
      db_delete('authmap')
        ->condition('uid', $account->uid)
        ->condition('module', $module[1])
        ->execute();
    }
  }
}