Unlock.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Customer\Controller\Adminhtml\Locks;
  8. use Magento\Customer\Model\AuthenticationInterface;
  9. use Magento\Framework\Controller\ResultFactory;
  10. use Magento\Backend\App\Action;
  11. /**
  12. * Unlock Customer Controller
  13. */
  14. class Unlock extends \Magento\Backend\App\Action
  15. {
  16. /**
  17. * Authorization level of a basic admin session
  18. *
  19. * @see _isAllowed()
  20. */
  21. const ADMIN_RESOURCE = 'Magento_Customer::manage';
  22. /**
  23. * Authentication
  24. *
  25. * @var AuthenticationInterface
  26. */
  27. protected $authentication;
  28. /**
  29. * Unlock constructor.
  30. *
  31. * @param Action\Context $context
  32. * @param AuthenticationInterface $authentication
  33. */
  34. public function __construct(
  35. Action\Context $context,
  36. AuthenticationInterface $authentication
  37. ) {
  38. parent::__construct($context);
  39. $this->authentication = $authentication;
  40. }
  41. /**
  42. * Unlock specified customer
  43. *
  44. * @return \Magento\Backend\Model\View\Result\Redirect
  45. */
  46. public function execute()
  47. {
  48. $customerId = $this->getRequest()->getParam('customer_id');
  49. try {
  50. // unlock customer
  51. if ($customerId) {
  52. $this->authentication->unlock($customerId);
  53. $this->getMessageManager()->addSuccess(__('Customer has been unlocked successfully.'));
  54. }
  55. } catch (\Exception $e) {
  56. $this->messageManager->addError($e->getMessage());
  57. }
  58. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  59. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  60. return $resultRedirect->setPath(
  61. 'customer/index/edit',
  62. ['id' => $customerId]
  63. );
  64. }
  65. }