ltsecurityinc安防产品在线商城代码
This commit is contained in:
app/code/Amasty/AdminActionsLog/Plugin/Security/Model/AdminSessionsManager/AddAdminSessionInfoId.php
Executable
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Plugin\Security\Model\AdminSessionsManager;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\ActiveSessionRepositoryInterface;
|
||||
use Magento\Backend\Model\Auth\Session;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
|
||||
class AddAdminSessionInfoId
|
||||
{
|
||||
/**
|
||||
* @var ActiveSessionRepositoryInterface
|
||||
*/
|
||||
private $activeSessionRepository;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
private $authSession;
|
||||
|
||||
public function __construct(
|
||||
ActiveSessionRepositoryInterface $activeSessionRepository,
|
||||
Session $authSession
|
||||
) {
|
||||
$this->activeSessionRepository = $activeSessionRepository;
|
||||
$this->authSession = $authSession;
|
||||
}
|
||||
|
||||
public function afterProcessLogin(): void
|
||||
{
|
||||
$sessionId = $this->authSession->getSessionId();
|
||||
$adminSessionInfoId = $this->authSession->getAdminSessionInfoId();
|
||||
|
||||
if (!empty($sessionId) && $adminSessionInfoId) {
|
||||
try {
|
||||
$activeSessionModel = $this->activeSessionRepository->getBySessionId($sessionId);
|
||||
} catch (NoSuchEntityException $exception) {
|
||||
return;
|
||||
}
|
||||
|
||||
$activeSessionModel->setAdminSessionInfoId((int)$adminSessionInfoId);
|
||||
$this->activeSessionRepository->save($activeSessionModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Plugin\Security\Model\AdminSessionsManager;
|
||||
|
||||
use Amasty\AdminActionsLog\Model\ActiveSession\ResourceModel\ActiveSession as ActiveSessionResource;
|
||||
use Magento\Backend\Model\Auth\Session;
|
||||
use Magento\Security\Model\AdminSessionInfo;
|
||||
use Magento\Security\Model\AdminSessionsManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class UpdateAdminSessionInfoId
|
||||
{
|
||||
/**
|
||||
* @var ActiveSessionResource
|
||||
*/
|
||||
private $activeSessionResource;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
private $authSession;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* Flag to mark when sessions validation has been passed
|
||||
* to prevent unnecessary queries.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isValid = false;
|
||||
|
||||
public function __construct(
|
||||
ActiveSessionResource $activeSessionResource,
|
||||
Session $authSession,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->activeSessionResource = $activeSessionResource;
|
||||
$this->authSession = $authSession;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function afterGetCurrentSession(
|
||||
AdminSessionsManager $subject,
|
||||
AdminSessionInfo $result
|
||||
): AdminSessionInfo {
|
||||
if (!$this->isValid) {
|
||||
$adminSessionInfoId = (int)$result->getId();
|
||||
if (!empty($this->authSession->getSessionId())
|
||||
&& $adminSessionInfoId
|
||||
&& ($user = $this->authSession->getUser())
|
||||
) {
|
||||
$userId = (int)$user->getId();
|
||||
try {
|
||||
$this->activeSessionResource->updateIfSessionInvalid($userId, $adminSessionInfoId);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->critical($e);
|
||||
}
|
||||
}
|
||||
$this->isValid = true;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user