mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 09:17:35 +00:00
- removed @since 2.0.0 as it is a base release - updated version in @since and @deprecated tag taking into account all patch releases
61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
|
|
namespace Magento\User\Controller\Adminhtml\User;
|
|
|
|
use Magento\Integration\Api\AdminTokenServiceInterface;
|
|
|
|
/**
|
|
* Class InvalidateToken - used to invalidate/revoke all authentication tokens for a specific user.
|
|
*/
|
|
class InvalidateToken extends \Magento\User\Controller\Adminhtml\User
|
|
{
|
|
/**
|
|
* @var AdminTokenServiceInterface
|
|
*/
|
|
protected $tokenService;
|
|
|
|
/**
|
|
* Inject dependencies.
|
|
*
|
|
* @param \Magento\Backend\App\Action\Context $context
|
|
* @param \Magento\Framework\Registry $coreRegistry
|
|
* @param \Magento\User\Model\UserFactory $userFactory
|
|
* @param AdminTokenServiceInterface $tokenService
|
|
*/
|
|
public function __construct(
|
|
\Magento\Backend\App\Action\Context $context,
|
|
\Magento\Framework\Registry $coreRegistry,
|
|
\Magento\User\Model\UserFactory $userFactory,
|
|
AdminTokenServiceInterface $tokenService
|
|
) {
|
|
parent::__construct($context, $coreRegistry, $userFactory);
|
|
$this->tokenService = $tokenService;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function execute()
|
|
{
|
|
if ($userId = $this->getRequest()->getParam('user_id')) {
|
|
try {
|
|
$this->tokenService->revokeAdminAccessToken($userId);
|
|
$this->messageManager->addSuccess(__('You have revoked the user\'s tokens.'));
|
|
$this->_redirect('adminhtml/*/edit', ['user_id' => $userId]);
|
|
return;
|
|
} catch (\Exception $e) {
|
|
$this->messageManager->addError($e->getMessage());
|
|
$this->_redirect('adminhtml/*/edit', ['user_id' => $userId]);
|
|
return;
|
|
}
|
|
}
|
|
$this->messageManager->addError(__('We can\'t find a user to revoke.'));
|
|
$this->_redirect('adminhtml/*');
|
|
}
|
|
}
|