user_external_login_register

6 user.module user_external_login_register($name, $module)
7 user.module user_external_login_register($name, $module)
8 user.module user_external_login_register($name, $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

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

Code

function user_external_login_register($name, $module) {
  $account = user_external_load($name);
  if (!$account) {
    // Register this new user.
    $account = entity_create('user', array(
      'name' => $name, 
      'pass' => user_password(), 
      'init' => $name, 
      'status' => 1, 
      'access' => REQUEST_TIME,
    ));
    $status = $account->save();
    // Terminate if an error occurred while saving the account.
    if ($status != SAVED_NEW) {
      drupal_set_message(t("Error saving user account."), 'error');
      return;
    }
    user_set_authmaps($account, array("authname_$module" => $name));
  }

  // Log user in.
  $form_state['uid'] = $account->uid;
  user_login_submit(array(), $form_state);
}
Login or register to post comments