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 426
Drush User Management commands

Code

function drush_user_login($user = NULL, $path = NULL) {
  // Fix up arguments based on our assumptions.
  $user_object = $uid = FALSE;
  $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 {
      $link = $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)) {
      // A user option was passed, prefer that to the user argument.
      $user = NULL;
      // 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];
      }
    }
    else if (empty($user)) {
      // No user option or argument was passed, so we default to uid 1.
      $uid = 1;
    }

    // Try to load a user from provided options and arguments.
    if ($uid || $uid = reset(_drush_user_get_users_from_options_and_arguments($user))) {
      if ($user_object = user_load($uid)) {
        if ($user_object->status) {
          $options = array();
          if ($path) {
            $options['query']['destination'] = $path;
          }
          $link = url(user_pass_reset_url($user_object) . '/login', $options);
        }
        else {
          return drush_set_error("The user account $uid is blocked.");
        }
      }
      else {
        return drush_set_error("The user account for uid $uid could not be loaded.");
      }
    }
    else {
      return FALSE; // An error has already been logged.
    }
  }

  drush_start_browser($link);
  return $link;
}