Ejemplo n.º 1
0
 public function testTokenExistsForEmail()
 {
     $email = '*****@*****.**';
     $file_name = getenv('HOME') . "/.terminus/tokens/{$email}";
     exec("rm {$file_name}");
     $this->assertFalse($this->tokens_cache->tokenExistsForEmail($email));
     $this->tokens_cache->add(compact('email'));
     $this->assertTrue($this->tokens_cache->tokenExistsForEmail($email));
     exec("rm {$file_name}");
 }
Ejemplo n.º 2
0
Archivo: Auth.php Proyecto: dalin-/cli
 /**
  * Execute the login based on a machine token
  *
  * @param string[] $args Elements as follow:
  *   string token Machine token to initiate login with
  *   string email Email address to locate token with
  * @return bool True if login succeeded
  * @throws TerminusException
  */
 public function logInViaMachineToken($args)
 {
     if (isset($args['token'])) {
         $token = $args['token'];
     } elseif (isset($args['email'])) {
         $token = $this->tokens_cache->findByEmail($args['email'])['token'];
         if (!$token) {
             throw new TerminusException('No machine token for "{email}" found.', compact('email'), 1);
         }
         $this->logger->info('Found a machine token for "{email}".', ['email' => $args['email']]);
     }
     $options = array('headers' => array('Content-type' => 'application/json'), 'form_params' => array('machine_token' => $token, 'client' => 'terminus'));
     $this->logger->info('Logging in via machine token');
     $response = $this->request->request('authorize', '', '', 'POST', $options);
     if (!$response || !isset($response['status_code']) || $response['status_code'] != '200') {
         throw new TerminusException('The provided machine token is not valid.', [], 1);
     }
     $data = $response['data'];
     $this->setInstanceData($response['data']);
     $user = Session::getUser();
     $user->fetch();
     $user_data = $user->serialize();
     $this->logger->info('Logged in as {email}.', ['email' => $user_data['email']]);
     if (isset($args['token'])) {
         $this->tokens_cache->add(['email' => $user_data['email'], 'token' => $token]);
     }
     return true;
 }