Ejemplo n.º 1
1
/**
 * Logs in with Behad credentials to enable Behat fixture use
 *
 * @return void
 */
function logInWithBehatCredentials()
{
    $creds = getBehatCredentials();
    $options = ['logger' => getLogger()];
    $auth = new AuthHelper($options);
    $auth->logInViaUsernameAndPassword($creds['username'], $creds['password']);
}
Ejemplo n.º 2
0
/**
 * Logs in with Behad credentials to enable Behat fixture use
 *
 * @return void
 */
function logInWithBehatCredentials()
{
    $creds = getBehatCredentials();
    $command = new ArtCommand(['runner' => new Runner()]);
    $auth = new AuthHelper(compact('command'));
    $auth->logInViaUsernameAndPassword($creds['username'], $creds['password']);
}
Ejemplo n.º 3
0
 public function testTokenExistsForEmail()
 {
     $tokens_cache = new TokensCache();
     $tokens_dir = $tokens_cache->getCacheDir();
     $creds = getBehatCredentials();
     $file_name = $tokens_dir . '/' . $creds['username'];
     setOutputDestination($file_name);
     $this->assertTrue($this->auth->tokenExistsForEmail($creds['username']));
     resetOutputDestination($file_name);
     $this->assertFalse($this->auth->tokenExistsForEmail('invalid'));
 }
Ejemplo n.º 4
0
 /**
  * Log in as a user
  *
  *  ## OPTIONS
  * [<email>]
  * : Email address to log in as.
  *
  * [--password=<value>]
  * : Log in non-interactively with this password. Useful for automation.
  *
  * [--machine-token=<value>]
  * : Authenticates using a machine token from your dashboard. Stores the
  *   token for future use.
  *
  * [--debug]
  * : dump call information when logging in.
  */
 public function login($args, $assoc_args)
 {
     if (!empty($args)) {
         $email = array_shift($args);
     }
     if (isset($assoc_args['machine-token']) && $assoc_args['machine-token'] !== true) {
         // Try to log in using a machine token, if provided.
         $token_data = ['token' => $assoc_args['machine-token']];
         $this->auth->logInViaMachineToken($token_data);
     } elseif (isset($email) && !isset($assoc_args['password']) && $this->auth->tokenExistsForEmail($email)) {
         // Try to log in using a machine token, if the account email was provided.
         $this->auth->logInViaMachineToken(compact('email'));
     } elseif (empty($args) && isset($_SERVER['TERMINUS_MACHINE_TOKEN'])) {
         // Try to log in using a machine token, if it's in the $_SERVER.
         $token_data = ['token' => $_SERVER['TERMINUS_MACHINE_TOKEN']];
         $this->auth->logInViaMachineToken($token_data);
     } elseif (isset($_SERVER['TERMINUS_USER']) && !isset($assoc_args['password']) && $this->auth->tokenExistsForEmail($_SERVER['TERMINUS_USER'])) {
         // Try to log in using a machine token, if $_SERVER provides account email.
         $this->auth->logInViaMachineToken(['email' => $_SERVER['TERMINUS_USER']]);
     } elseif (!isset($email) && ($only_token = $this->auth->getOnlySavedToken())) {
         // Try to log in using a machine token, if there is only one saved token.
         $this->auth->logInViaMachineToken(['email' => $only_token['email']]);
     } else {
         if (isset($email) && isset($assoc_args['password'])) {
             $password = $assoc_args['password'];
             $this->auth->logInViaUsernameAndPassword($email, $assoc_args['password']);
         } else {
             $this->log()->info("Please visit the Dashboard to generate a machine token:\n{url}", ['url' => $this->auth->getMachineTokenCreationUrl()]);
             exit(1);
         }
     }
     $this->log()->debug(get_defined_vars());
     Terminus::launchSelf('art', array('fist'));
 }