Skip to content

Commit

Permalink
Initial SS4 upgrade work
Browse files Browse the repository at this point in the history
  • Loading branch information
kinglozzer committed Apr 24, 2019
1 parent 2cb8ba9 commit fb5bf79
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 235 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea/
6 changes: 0 additions & 6 deletions _config.php

This file was deleted.

25 changes: 17 additions & 8 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
---
Name: masqueradeconfig
---
Member:
SilverStripe\Admin\SecurityAdmin:
extensions:
- MasqueradeMemberExtension
SecurityAdmin:
- DHensby\SilverStripeMasquerade\Extensions\SecurityAdminExtension
SilverStripe\Security\Member:
extensions:
- MasqueradeSecurityAdminExtension
LeftAndMain:
extra_requirements_css:
masquerade/css/masquerade.css:
media: screen
- DHensby\SilverStripeMasquerade\Extensions\MemberExtension
---
Name: masquerademiddleware
After:
- '#coresecurity'
---
SilverStripe\Core\Injector\Injector:
SilverStripe\Control\Director:
properties:
Middlewares:
MasqueradeMiddleware: '%$DHensby\SilverStripeMasquerade\Control\MasqueradeMiddleware'
SilverStripe\Security\MemberAuthenticator\LogoutHandler:
extensions:
- DHensby\SilverStripeMasquerade\Extensions\LogoutHandlerExtension
9 changes: 0 additions & 9 deletions _config/routes.yml

This file was deleted.

35 changes: 0 additions & 35 deletions code/Extensions/MasqueradeMemberExtension.php

This file was deleted.

18 changes: 0 additions & 18 deletions code/Extensions/MasqueradeSecurityAdminExtension.php

This file was deleted.

26 changes: 0 additions & 26 deletions code/controllers/MasqueradeSecurityController.php

This file was deleted.

88 changes: 0 additions & 88 deletions code/forms/gridfield/GridFieldMasqueradeButton.php

This file was deleted.

20 changes: 0 additions & 20 deletions code/forms/gridfield/MasqueradeGridFieldDetailForm_ItemRequest.php

This file was deleted.

17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "dhensby/silverstripe-masquerade",
"description": "SilverStripe module to allow you to masquerade as other users",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"require": {
"php": "^5.3.3 || ^7",
"silverstripe/framework": "^3.1.0"
"silverstripe/framework": "^4"
},
"require-dev": {
"phpunit/phpunit": "^3 || ^4 || ^5"
"phpunit/phpunit": "^5.7"
},
"autoload": {
"psr-4": {
"DHensby\\SilverStripeMasquerade\\": "src/"
}
},
"license": "ISC",
"authors": [
Expand All @@ -18,9 +22,8 @@
],
"extra": {
"branch-alias": {
"master-dev": "0.x-dev"
},
"installer-name": "masquerade"
"dev-master": "1.x-dev"
}
},
"prefer-stable": true,
"minimum-stability": "dev"
Expand Down
17 changes: 0 additions & 17 deletions css/masquerade.css

This file was deleted.

24 changes: 24 additions & 0 deletions src/Control/MasqueradeMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace DHensby\SilverStripeMasquerade\Control;

use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Middleware\HTTPMiddleware;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;

class MasqueradeMiddleware implements HTTPMiddleware
{
public function process(HTTPRequest $request, callable $delegate)
{
$session = $request->getSession();
if ($session->isStarted() && $id = $session->get('masqueradingAs')) {
$member = Member::get()->byID($id);
if ($member) {
Security::setCurrentUser($member);
}
}

return $delegate($request);
}
}
52 changes: 52 additions & 0 deletions src/Extensions/LogoutHandlerExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace DHensby\SilverStripeMasquerade\Extensions;

use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Extension;
use SilverStripe\Security\Security;

class LogoutHandlerExtension extends Extension
{
public function beforeLogout()
{
/** @var HTTPRequest $request */
$request = $this->owner->getRequest();
$session = $request->getSession();

// If we're currently masquerading, we only want to stop masquerading, not *actually* log out
if ($session->get('masqueradingAs')) {
$session->clear('masqueradingAs');
$session->save($request);
$response = $this->redirectAfterLogout();
$response->output();
exit;
}
}

/**
* Copied verbatim from LogoutHandler::redirectAfterLogout()
*
* @return HTTPResponse
*/
protected function redirectAfterLogout()
{
$backURL = $this->owner->getBackURL();
if ($backURL) {
return $this->owner->redirect($backURL);
}

$link = Security::config()->get('login_url');
$referer = $this->owner->getReturnReferer();
if ($referer) {
$link = Controller::join_links($link, '?' . http_build_query([
'BackURL' => Director::makeRelative($referer)
]));
}

return $this->owner->redirect($link);
}
}
Loading

0 comments on commit fb5bf79

Please sign in to comment.