function drush_user_login

8.0.x user.drush.inc drush_user_login($inputs = '', $path = NULL)
6.x user.drush.inc drush_user_login($user = NULL, $path = NULL)
7.x user.drush.inc drush_user_login($inputs = '', $path = NULL)
4.x user.drush.inc drush_user_login($name = NULL)
5.x user.drush.inc drush_user_login($user = NULL, $path = NULL)
master user.drush.inc drush_user_login($inputs = '', $path = NULL)

Displays a one time login link for the given user.

File

commands/user/user.drush.inc, line 372
Drush User Management commands

Code

function drush_user_login($inputs = '', $path = NULL) {
  $args = func_get_args();

  // Redispatch if called against a remote-host so a browser is started on the
  // the *local* machine.
  $alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS');
  if (drush_sitealias_is_remote_site($alias)) {
    $return = drush_invoke_process($alias, 'user-login', $args, drush_redispatch_get_options(), array('integrate' => FALSE));
    if ($return['error_status']) {
      return drush_set_error('Unable to execute user login.');
    }
    else {
      // Prior versions of Drupal returned a string so cast to an array if needed.
      $links = is_string($return['object']) ? array($return['object']) : $return['object'];
    }
  }
  else {
    if (!drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
      // Fail gracefully if unable to bootstrap Drupal.
      // drush_bootstrap() has already logged an error.
      return FALSE;
    }

    if (drush_get_option('uid', FALSE) || drush_get_option('name', FALSE) || drush_get_option('mail', FALSE)) {
      // If we only have a single argument and one of the user options is passed,
      // then we assume the argument is the path to open.
      if (count($args) == 1) {
        $path = $args[0];
      }
    }

    // Try to load a user from provided options and arguments.
    try {
      $userlist = new UserList($inputs);
    }
    catch (UserListException $e) {
      // No user option or argument was passed, so we default to uid 1.
      $userlist = new UserList(1);
    }
    $links = $userlist->each('passResetUrl', array($path));
  }
  $port = drush_get_option('redirect-port', FALSE);
  // There is almost always only one link so pick the first one for display and browser.
  // The full array is sent on backend calls.
  $first = current($links);
  drush_start_browser($first, FALSE, $port);
  drush_backend_set_result($links);
  return $first;
}