public function testFindByEmail() { $email = '*****@*****.**'; $this->tokens_cache->add(compact('email')); $contents = $this->tokens_cache->findByEmail($email); $this->assertEquals($contents['email'], $email); $file_name = getenv('HOME') . "/.terminus/tokens/{$email}"; exec("rm {$file_name}"); try { $this->tokens_cache->findByEmail($email); } catch (\Exception $e) { $message = $e->getMessage(); } $this->assertTrue(isset($message)); }
/** * 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; }