Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CheckUserEditObserver.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
21  const FORM_ID = 'user_edit';
22 
26  protected $helper;
27 
31  protected $actionFlag;
32 
36  protected $messageManager;
37 
41  protected $redirect;
42 
47 
53  protected $authentication;
54 
58  protected $customerSession;
59 
63  protected $scopeConfig;
64 
75  public function __construct(
76  \Magento\Captcha\Helper\Data $helper,
77  \Magento\Framework\App\ActionFlag $actionFlag,
78  \Magento\Framework\Message\ManagerInterface $messageManager,
79  \Magento\Framework\App\Response\RedirectInterface $redirect,
84  ) {
85  $this->helper = $helper;
86  $this->actionFlag = $actionFlag;
87  $this->messageManager = $messageManager;
88  $this->redirect = $redirect;
89  $this->captchaStringResolver = $captchaStringResolver;
90  $this->authentication = $authentication;
91  $this->customerSession = $customerSession;
92  $this->scopeConfig = $scopeConfig;
93  }
94 
101  public function execute(\Magento\Framework\Event\Observer $observer)
102  {
103  $captchaModel = $this->helper->getCaptcha(self::FORM_ID);
104  if ($captchaModel->isRequired()) {
106  $controller = $observer->getControllerAction();
107  if (!$captchaModel->isCorrect(
108  $this->captchaStringResolver->resolve(
109  $controller->getRequest(),
111  )
112  )) {
113  $customerId = $this->customerSession->getCustomerId();
114  $this->authentication->processAuthenticationFailure($customerId);
115  if ($this->authentication->isLocked($customerId)) {
116  $this->customerSession->logout();
117  $this->customerSession->start();
118  $message = __(
119  'The account is locked. Please wait and try again or contact %1.',
120  $this->scopeConfig->getValue('contact/email/recipient_email')
121  );
122  $this->messageManager->addError($message);
123  }
124  $this->messageManager->addError(__('Incorrect CAPTCHA'));
125  $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
126  $this->redirect->redirect($controller->getResponse(), '*/*/edit');
127  }
128  }
129 
130  $customer = $this->customerSession->getCustomer();
131  $login = $customer->getEmail();
132  $captchaModel->logAttempt($login);
133 
134  return $this;
135  }
136 }
$customer
Definition: customers.php:11
__()
Definition: __.php:13
$message
__construct(\Magento\Captcha\Helper\Data $helper, \Magento\Framework\App\ActionFlag $actionFlag, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Framework\App\Response\RedirectInterface $redirect, CaptchaStringResolver $captchaStringResolver, AuthenticationInterface $authentication, Session $customerSession, ScopeConfigInterface $scopeConfig)
$controller
Definition: info.phtml:14