Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW Add onBeforeRemoveLoginSession extension hook #34

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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