1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Controller\Adminhtml\Customer;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Integration\Api\CustomerTokenServiceInterface;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Api\Data\AddressInterfaceFactory;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
use Magento\Customer\Model\Address\Mapper;
use Magento\Framework\DataObjectFactory;
use Magento\Framework\Api\DataObjectHelper;
/**
* Class to invalidate tokens for customers
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.NumberOfChildren)
*/
class InvalidateToken extends \Magento\Customer\Controller\Adminhtml\Index implements HttpGetActionInterface
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Customer::invalidate_tokens';
/**
* @var CustomerTokenServiceInterface
*/
protected $tokenService;
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Magento\Customer\Model\CustomerFactory $customerFactory
* @param \Magento\Customer\Model\AddressFactory $addressFactory
* @param \Magento\Customer\Model\Metadata\FormFactory $formFactory
* @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory
* @param \Magento\Customer\Helper\View $viewHelper
* @param \Magento\Framework\Math\Random $random
* @param CustomerRepositoryInterface $customerRepository
* @param \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter
* @param Mapper $addressMapper
* @param AccountManagementInterface $customerAccountManagement
* @param AddressRepositoryInterface $addressRepository
* @param CustomerInterfaceFactory $customerDataFactory
* @param AddressInterfaceFactory $addressDataFactory
* @param \Magento\Customer\Model\Customer\Mapper $customerMapper
* @param \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor
* @param DataObjectHelper $dataObjectHelper
* @param DataObjectFactory $objectFactory
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
* @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param CustomerTokenServiceInterface $tokenService
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
\Magento\Customer\Model\CustomerFactory $customerFactory,
\Magento\Customer\Model\AddressFactory $addressFactory,
\Magento\Customer\Model\Metadata\FormFactory $formFactory,
\Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
\Magento\Customer\Helper\View $viewHelper,
\Magento\Framework\Math\Random $random,
CustomerRepositoryInterface $customerRepository,
\Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter,
Mapper $addressMapper,
AccountManagementInterface $customerAccountManagement,
AddressRepositoryInterface $addressRepository,
CustomerInterfaceFactory $customerDataFactory,
AddressInterfaceFactory $addressDataFactory,
\Magento\Customer\Model\Customer\Mapper $customerMapper,
\Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
DataObjectHelper $dataObjectHelper,
DataObjectFactory $objectFactory,
\Magento\Framework\View\LayoutFactory $layoutFactory,
\Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
CustomerTokenServiceInterface $tokenService
) {
$this->tokenService = $tokenService;
parent::__construct(
$context,
$coreRegistry,
$fileFactory,
$customerFactory,
$addressFactory,
$formFactory,
$subscriberFactory,
$viewHelper,
$random,
$customerRepository,
$extensibleDataObjectConverter,
$addressMapper,
$customerAccountManagement,
$addressRepository,
$customerDataFactory,
$addressDataFactory,
$customerMapper,
$dataObjectProcessor,
$dataObjectHelper,
$objectFactory,
$layoutFactory,
$resultLayoutFactory,
$resultPageFactory,
$resultForwardFactory,
$resultJsonFactory
);
}
/**
* Reset customer's tokens handler
*
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
if ($customerId = $this->getRequest()->getParam('customer_id')) {
try {
$this->tokenService->revokeCustomerAccessToken($customerId);
$this->messageManager->addSuccess(__('You have revoked the customer\'s tokens.'));
$resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]);
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$resultRedirect->setPath('customer/index/edit', ['id' => $customerId, '_current' => true]);
}
} else {
$this->messageManager->addError(__('We can\'t find a customer to revoke.'));
$resultRedirect->setPath('customer/index/index');
}
return $resultRedirect;
}
}