public function testGetOnlySavedToken() { $tokens_cache = new TokensCache(); $tokens_dir = $tokens_cache->getCacheDir(); $token_count = count(scandir($tokens_dir)) - 2; $only_token = $this->auth->getOnlySavedToken(); if ($token_count != 1) { $this->assertFalse($only_token); } else { $this->assertInternalType('array', $only_token); } }
/** * Ensures the user is logged in or errs. * * @return bool Always true * @throws TerminusException */ public static function ensureLogin() { $session = Session::instance()->getData(); $auth = new Auth(); if (!$auth->loggedIn()) { if ($token = $auth->getOnlySavedToken()) { $auth->logInViaMachineToken($token); } else { if (isset($_SERVER['TERMINUS_MACHINE_TOKEN']) && ($token = $_SERVER['TERMINUS_MACHINE_TOKEN'])) { $auth->logInViaMachineToken(compact('token')); } else { if (isset($_SERVER['TERMINUS_USER']) && ($email = $_SERVER['TERMINUS_USER'])) { $auth->logInViaMachineToken(compact('email')); } else { $message = 'You are not logged in. Run `auth login` to '; $message .= 'authenticate or `help auth login` for more info.'; $auth->logger->warning($message); exit(1); } } } } return true; }