Skip to content

Commit

Permalink
Moved log-out function out of AuthCommand and into Auth model
Browse files Browse the repository at this point in the history
  • Loading branch information
Sara McCutcheon committed May 2, 2016
1 parent c26ae2b commit fb3ee44
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project starting with the 0.6.0 release will be docu
- Removed the port number from the create-a-machine token URL seen when using `auth login` except for when the host is localhost. (#1034)
- Changed the `SynopsisValidator` so that any unnamed command argument between `<` and `>` may be given any name. (#1041)
- When running `site deploy` and there are no changes to deploy, Terminus will now exit with status `0` rather than `1`. (#1054)
- Moved log-out function out of `AuthCommand` and into the `Auth` model. (#1058)

### Fixed
- `wp` and `drush` commands both now use the object buffer and output the result of the operation without formatting. (#1023)
Expand Down
24 changes: 17 additions & 7 deletions php/Terminus/Commands/AuthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
* @command auth
*/
class AuthCommand extends TerminusCommand {
/**
* @var Auth
*/
private $auth;

/**
* Object constructor
*
* @param array $options Options to construct the command object
* @return AuthCommand
*/
public function __construct(array $options = []) {
parent::__construct($options);
$this->auth = new Auth();
}

/**
* Log in as a user
Expand All @@ -31,7 +46,7 @@ class AuthCommand extends TerminusCommand {
* : dump call information when logging in.
*/
public function login($args, $assoc_args) {
$auth = new Auth();
$auth = $this->auth;
$tokens = $auth->getAllSavedTokenEmails();
if (!empty($args)) {
$email = array_shift($args);
Expand All @@ -53,11 +68,6 @@ public function login($args, $assoc_args) {
);
$auth->logInViaMachineToken(compact('email'));
$this->log()->info('Logging in via machine token');
} 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']];
$auth->logInViaMachineToken($token_data);
$this->log()->info('Logging in via machine token');
} elseif (isset($_SERVER['TERMINUS_USER'])
&& !isset($assoc_args['password'])
&& $auth->tokenExistsForEmail($_SERVER['TERMINUS_USER'])
Expand Down Expand Up @@ -118,7 +128,7 @@ public function login($args, $assoc_args) {
*/
public function logout() {
$this->log()->info('Logging out of Pantheon.');
$this->cache->remove('session');
$this->auth->logOut();
}

/**
Expand Down
9 changes: 9 additions & 0 deletions php/Terminus/Models/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ public function logInViaUsernameAndPassword($email, $password) {
return true;
}

/**
* Logs the current user out of their Pantheon session
*
* @return void
*/
public function logOut() {
Session::destroy();
}

/**
* Checks to see whether the email has been set with a machine token
*
Expand Down
21 changes: 18 additions & 3 deletions php/Terminus/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Session {
* @var Session
*/
public static $instance;
/**
* @var FileCache
*/
protected static $cache;
/**
* @var object
*/
Expand All @@ -19,16 +23,27 @@ class Session {
* Instantiates object, sets session data
*/
public function __construct() {
$cache = new FileCache();
$session = $cache->getData('session');
$this->data = $session;
self::$cache = new FileCache();
$session = self::$cache->getData('session');
$this->data = $session;
if (empty($session)) {
$this->data = new \stdClass();
}

self::$instance = $this;
}

/**
* Removes the session from the cache
*
* @return void
*/
public static function destroy() {
self::$cache->remove('session');
}

/**
* Retrieves session data
/**
* Returns given data property or default if DNE.
*
Expand Down

0 comments on commit fb3ee44

Please sign in to comment.