dt('Generates one-time use login link for the specified user.'), 'arguments' => array( 'uid' => dt('The ID of the user you wish to login as. Defaults to 1.'), ), 'options' => array( 'name'=> dt('The username of the user you wish to log in as.'), ), 'examples' => array( 'drush login-link --uri=http://example.com' => dt('Generate a link to log in to the site "http://example.com'), 'drush login-link --name=example' => dt('Generate a link to log in as the user with username "example"'), 'drush login-link 555' => dt('Generate a link to log in as the user with ID "555"'), ), 'aliases' => array('ll'), ); return $items; } function drush_login_link($uid = NULL) { global $base_url; // Get the base URLs. $base_urls = array(); if ($base_url && $base_url != 'http://default') { $base_urls[] = $base_url; } else { // @todo SUBSTRING_INDEX is MySQL-only. // Get all characters up to the port or path. $query = << $name); } elseif ($uid) { $array = array('uid' => $uid); } else { $array = array('uid' => 1); } $account = user_load($array); // Print the login links. if ($account) { // format_plural() may not be available. if (count($base_urls) == 1) { drush_log(dt('Use the following URL to log in to your site:'), 'success'); } else { drush_log(dt('Use one of the following URLs to log in to your site:'), 'success'); } foreach ($base_urls as $base_url) { drush_log(login_link_url($account, $base_url), 'ok'); } } else { if ($name) { drush_log(dt('Unable to find a user with the username "@name"', array('@name' => $name)), 'error'); } else { drush_log(dt('Unable to find a user with the ID "@uid"', array('@uid' => $uid)), 'error'); } } } /** * @see user_pass_reset_url() */ function login_link_url($account, $base_url) { $timestamp = time(); return url("user/reset/$account->uid/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login) . '/login', array( 'absolute' => $base_url != 'http://default', 'base_url' => $base_url, 'query' => array('destination' => ''), )); }