You are here

function subuser_switch_user in Subuser 8

Same name and namespace in other branches
  1. 6 subuser.module \subuser_switch_user()
  2. 7.2 switch/subuser_switch.module \subuser_switch_user()

Switch to the active user to another account.

After switching the user will be redirected to /user and the parent user will be stored in $_SESSION['subuser_parent'].

Parameters

$account: The user account to switch to.

1 call to subuser_switch_user()
subuser_switch_user_operations_switch in switch/subuser_switch.module
Callback for subuser switch user operation.
1 string reference to 'subuser_switch_user'
subuser_switch_menu in switch/subuser_switch.module
Implements hook_menu().

File

switch/subuser_switch.module, line 106
Provides primary Drupal hook implementations.

Code

function subuser_switch_user($account) {
  global $user;
  if ($user->uid) {
    module_invoke_all('user_logout', $user);
  }
  if (!isset($_SESSION['subuser_parent']) || $account->uid != $_SESSION['subuser_parent']) {
    $parent = $user->uid;
  }
  $user = $account;
  drupal_session_regenerate();
  $edit = array();
  user_module_invoke('login', $edit, $user);
  if (isset($parent)) {
    $_SESSION['subuser_parent'] = $parent;
    drupal_goto('user');
  }
  unset($_SESSION['subuser_parent']);
  drupal_goto('user/' . $user->uid . '/subuser');
}