Skip to content

Commit

Permalink
NEW Add onBeforeRemoveLoginSession extension hook
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Mar 23, 2021
1 parent ad407bb commit a1ac0a9
Show file tree
Hide file tree
Showing 3 changed files with 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
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
*/
class LoginSessionController extends LeftAndMain
{
private static $url_segment = 'loginsession';

// TODO: this is probably a legacy config that's not used anywhere so should be deleted
private static $ignore_menuitem = true;

private static $url_handlers = [
Expand Down Expand Up @@ -62,6 +55,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 a1ac0a9

Please sign in to comment.