Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvalidateToken.php
Go to the documentation of this file.
1 <?php
9 
11 
16 {
20  protected $tokenService;
21 
30  public function __construct(
31  \Magento\Backend\App\Action\Context $context,
32  \Magento\Framework\Registry $coreRegistry,
33  \Magento\User\Model\UserFactory $userFactory,
35  ) {
36  parent::__construct($context, $coreRegistry, $userFactory);
37  $this->tokenService = $tokenService;
38  }
39 
43  public function execute()
44  {
45  if ($userId = $this->getRequest()->getParam('user_id')) {
46  try {
47  $this->tokenService->revokeAdminAccessToken($userId);
48  $this->messageManager->addSuccess(__('You have revoked the user\'s tokens.'));
49  $this->_redirect('adminhtml/*/edit', ['user_id' => $userId]);
50  return;
51  } catch (\Exception $e) {
52  $this->messageManager->addError($e->getMessage());
53  $this->_redirect('adminhtml/*/edit', ['user_id' => $userId]);
54  return;
55  }
56  }
57  $this->messageManager->addError(__('We can\'t find a user to revoke.'));
58  $this->_redirect('adminhtml/*');
59  }
60 }
__()
Definition: __.php:13
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\User\Model\UserFactory $userFactory, AdminTokenServiceInterface $tokenService)