Skip to content

Commit

Permalink
Merge pull request #34 from creative-commoners/pulls/1/auditor
Browse files Browse the repository at this point in the history
NEW Add onBeforeRemoveLoginSession extension hook
  • Loading branch information
bergice authored Mar 29, 2021
2 parents bcbed66 + 5a6b0d0 commit 4901f43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"symbiote/silverstripe-queuedjobs": "^4"
},
"suggest": {
"symbiote/silverstripe-queuedjobs": "^4"
"symbiote/silverstripe-queuedjobs": "^4",
"silverstripe/auditor": "^2.3"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 4 additions & 8 deletions src/Middleware/LoginSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
use SilverStripe\Security\SecurityToken;
use SilverStripe\SessionManager\Model\LoginSession;

/**
* Class LoginSessionController
* @package SilverStripe\SessionManager\Control
*/
// TODO: move this to Controllers folder and extend Controller instead of LeftAndMain
class LoginSessionController extends LeftAndMain
{
private static $url_segment = 'loginsession';

// TODO: remove this when no longer extending LeftAndMain
private static $ignore_menuitem = true;

private static $url_handlers = [
Expand Down Expand Up @@ -62,6 +56,8 @@ public function removeLoginSession(HTTPRequest $request): HTTPResponse
);
}

$this->extend('onBeforeRemoveLoginSession', $loginSession);

$loginSession->delete();

return $this->jsonResponse([
Expand Down
6 changes: 4 additions & 2 deletions src/Security/LogInAuthenticationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,17 @@ public function logIn(Member $member, $persistent = false, HTTPRequest $request
}

$loginSession->LastAccessed = DBDatetime::now()->Rfc2822();
$loginSession->IPAddress = $request->getIP();
$loginSession->IPAddress = $request ? $request->getIP() : '';
$loginSession->write();

if ($persistent && $rememberLoginHash = $this->getRememberLoginHash()) {
$rememberLoginHash->LoginSessionID = $loginSession->ID;
$rememberLoginHash->write();
}

$request->getSession()->set($this->getSessionVariable(), $loginSession->ID);
if ($request) {
$request->getSession()->set($this->getSessionVariable(), $loginSession->ID);
}
}

/**
Expand Down

0 comments on commit 4901f43

Please sign in to comment.