/** * Determines if user is logged in * * @return [boolean] True if user is logged in */ public static function loggedIn() { if (Session::instance()->getValue('session', false) === false) { throw new TerminusException('Please login first with `terminus auth login`'); } return true; }
public function __construct() { # Load commonly used data from cache. $this->cache = Terminus::get_cache(); $this->session = Session::instance(); $this->sites = $this->cache->get_data('sites'); }
/** * Instantiates object, sets cache and session * * @return [TerminusCommand] $this */ public function __construct() { //Load commonly used data from cache $this->cache = Terminus::get_cache(); $this->logger = Terminus::get_logger(); $this->outputter = Terminus::get_outputter(); $this->session = Session::instance(); }
/** * Instantiates object, sets cache and session * * @return [TerminusCommand] $this */ public function __construct() { //Load commonly used data from cache $this->cache = Terminus::getCache(); $this->logger = Terminus::getLogger(); $this->outputter = Terminus::getOutputter(); $this->session = Session::instance(); if (!Terminus::isTest()) { $this->checkForUpdate(); } }
/** * Instantiates object, sets cache and session * * @param array $options Elements as follow: * FileCache cache * Logger Logger * Outputter Outputter * Session Session * @return TerminusCommand */ public function __construct(array $options = []) { $this->cache = new FileCache(); $this->runner = $options['runner']; $this->session = Session::instance(); $this->logger = $this->runner->getLogger(); $this->outputter = $this->runner->getOutputter(); $this->loadHelpers(); if (!Utils\isTest()) { Utils\checkForUpdate($this->log()); } }
/** * Sets up and fills a cookie jar * * @param [array] $params Request data to fill jar with * @return [GuzzleHttp\Cookie\CookieJar] $jar */ static function fillCookieJar($params) { $jar = new CookieJar(); $cookies = array(); if ($session = Session::instance()->get('session', false)) { $cookies['X-Pantheon-Session'] = $session; } if (isset($params['cookies'])) { $cookies = array_merge($cookies, $params['cookies']); } $jar->fromArray($cookies, ''); return $jar; }
public static function getData() { $session = Session::instance(); return $session->data; }
/** * Saves the session data to a cookie * * @param \stdClass $data Session data to save * @return bool Always true */ private function setInstanceData(\stdClass $data) { if (!isset($data->machine_token)) { $machine_token = (array) Session::instance()->get('machine_token'); } else { $machine_token = $data->machine_token; } $session = array('user_uuid' => $data->user_id, 'session' => $data->session, 'session_expire_time' => $data->expires_at); if ($machine_token && is_string($machine_token)) { $session['machine_token'] = $machine_token; } Session::instance()->setData($session); return true; }
/** * Object constructor, saves cache to cache property * * @return [SitesCache] $this */ public function __construct() { $this->cache = Terminus::getCache(); $this->cachekey = Session::instance()->get('user_uuid', '') . '_sites'; $this->request = new Request(); }
/** * Execute the login based on email,password * * @param $email string (required) * @param $password string (required) * @package Terminus * @version 0.04-alpha * @return string */ private function doLogin($email, $password) { if (Terminus::is_test()) { $data = array('user_uuid' => '77629472-3050-457c-8c3d-32b2cabf992b', 'session' => '77629472-3050-457c-8c3d-32b2cabf992b:7dc42f40-65f8-11e4-b314-bc764e100eb1:ZHR0TgtQYsKcOOwMOd0tk', 'session_expire_time' => '1417727066', 'email' => '*****@*****.**'); return $data; } $options = array('body' => json_encode(array('email' => $email, 'password' => $password)), 'headers' => array('Content-type' => 'application/json')); $response = Terminus_Command::request('login', '', '', 'POST', $options); if (!$response or '200' != @$response['info']['http_code']) { \Terminus::error("[auth_error]: unsuccessful login"); } // Prepare credentials for storage. $data = array('user_uuid' => $response['data']->user_id, 'session' => $response['data']->session, 'session_expire_time' => $response['data']->expires_at, 'email' => $email); // creates a session instance Session::instance()->setData($data); return $data; }
/** * Execute the login based on an existing session token * * @param $session_token string (required) * @return array */ private function doLoginFromSessionToken($session_token) { $options = array('headers' => array('Content-type' => 'application/json'), 'cookies' => array('X-Pantheon-Session' => $session_token)); # Temporarily disable the cache for this GET call $response = TerminusCommand::request('user', '', '', 'GET', $options); if (!$response or '200' != @$response['info']['http_code']) { $this->failure('Session token not valid'); } // Prepare credentials for storage. $data = array('user_uuid' => $response['data']->id, 'session' => $session_token, 'session_expire_time' => 0, 'email' => $response['data']->email); // creates a session instance Session::instance()->setData($data); return $data; }
/** * Includes every command file in the commands directory * * @param CompositeCommand $parent The parent command to add the new commands to * * @return void */ private static function loadAllCommands(CompositeCommand $parent) { // Create a list of directories where commands might live. $directories = array(); // Add the directory of core commands first. $directories[] = TERMINUS_ROOT . '/php/Terminus/Commands'; // Find the command directories from the third party plugins directory. foreach (self::getUserPlugins() as $dir) { $directories[] = "{$dir}/Commands/"; } // Include all class files in the command directories. foreach ($directories as $cmd_dir) { if ($cmd_dir && file_exists($cmd_dir)) { $iterator = new \DirectoryIterator($cmd_dir); foreach ($iterator as $file) { if ($file->isFile() && $file->isReadable() && $file->getExtension() == 'php') { include_once $file->getPathname(); } } } } // Find the defined command classes and add them to the given base command. $classes = get_declared_classes(); $options = ['cache' => self::getCache(), 'logger' => self::getLogger(), 'outputter' => self::getOutputter(), 'session' => Session::instance()]; foreach ($classes as $class) { $reflection = new \ReflectionClass($class); if ($reflection->isSubclassOf('Terminus\\Commands\\TerminusCommand')) { Dispatcher\CommandFactory::create($reflection->getName(), $parent, $options); } } }
/** * Saves the session data to a cookie * * @param [array] $data Session data to save * @return [boolean] Always true */ private function setInstanceData($data) { if (!isset($data->refresh)) { $refresh = (array) Session::instance()->get('refresh'); } else { $refresh = $data->refresh; } $session = array('user_uuid' => $data->user_id, 'session' => $data->session, 'session_expire_time' => $data->expires_at); if ($refresh && is_string($refresh)) { $session['refresh'] = $refresh; } Session::instance()->setData($session); return true; }
public function testInstance() { $session = Session::instance(); $this->assertInstanceOf('Terminus\\Session', $session); }
/** * Returnes session data indicated by the key * * @param [string] $key Name of session property to retrieve * @return [mixed] $session_property */ public static function getValue($key) { $session = Session::instance(); $session_property = $session->get($key); return $session_property; }
/** * Sends a request to the API * * @param string $uri URL for API request * @param string $method Request method (i.e. PUT, POST, DELETE, or GET) * @param array $arg_params Request parameters * @return \Psr\Http\Message\ResponseInterface */ private function send($uri, $method, array $arg_params = array()) { $extra_params = array('headers' => array('User-Agent' => $this->userAgent(), 'Content-type' => 'application/json'), RequestOptions::VERIFY => strpos(TERMINUS_HOST, 'onebox') === false); if ($session = Session::instance()->get('session', false)) { $extra_params['headers']['Authorization'] = "Bearer {$session}"; } $params = array_merge_recursive($extra_params, $arg_params); if (isset($params['form_params'])) { $params['json'] = $params['form_params']; unset($params['form_params']); } $params[RequestOptions::VERIFY] = strpos(TERMINUS_HOST, 'onebox') === false; $client = new Client(array('base_uri' => $this->getBaseUri(), 'cookies' => $this->fillCookieJar($params))); unset($params['cookies']); Runner::getLogger()->debug("#### REQUEST ####\nParams: {params}\nURI: {uri}\nMethod: {method}", array('params' => json_encode($params), 'uri' => $uri, 'method' => $method)); //Required objects and arrays stir benign warnings. error_reporting(E_ALL ^ E_WARNING); $request = new HttpRequest(ucwords($method), $uri, $params); error_reporting(E_ALL); $response = $client->send($request, $params); return $response; }
public static function loggedIn() { if (false === Session::instance()->getValue('session', false) and !Terminus::is_test()) { \Terminus::error("Please login first with `terminus auth login`"); } }