当前位置: 首页>>代码示例>>PHP>>正文


PHP SessionManagerInterface::setUsername方法代码示例

本文整理汇总了PHP中Magento\Framework\Session\SessionManagerInterface::setUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionManagerInterface::setUsername方法的具体用法?PHP SessionManagerInterface::setUsername怎么用?PHP SessionManagerInterface::setUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Session\SessionManagerInterface的用法示例。


在下文中一共展示了SessionManagerInterface::setUsername方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: aroundExecute

 /**
  * @param \Magento\Customer\Controller\Ajax\Login $subject
  * @param \Closure $proceed
  * @return $this
  * @throws \Zend_Json_Exception
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function aroundExecute(\Magento\Customer\Controller\Ajax\Login $subject, \Closure $proceed)
 {
     $captchaFormIdField = 'captcha_form_id';
     $captchaInputName = 'captcha_string';
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $subject->getRequest();
     $loginParams = [];
     $content = $request->getContent();
     if ($content) {
         $loginParams = \Zend_Json::decode($content);
     }
     $username = isset($loginParams['username']) ? $loginParams['username'] : null;
     $captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
     $loginFormId = isset($loginParams[$captchaFormIdField]) ? $loginParams[$captchaFormIdField] : null;
     foreach ($this->formIds as $formId) {
         $captchaModel = $this->helper->getCaptcha($formId);
         if ($captchaModel->isRequired($username) && !in_array($loginFormId, $this->formIds)) {
             $resultJson = $this->resultJsonFactory->create();
             return $resultJson->setData(['errors' => true, 'message' => __('Provided form does not exist')]);
         }
         if ($formId == $loginFormId) {
             $captchaModel->logAttempt($username);
             if (!$captchaModel->isCorrect($captchaString)) {
                 $this->sessionManager->setUsername($username);
                 /** @var \Magento\Framework\Controller\Result\Json $resultJson */
                 $resultJson = $this->resultJsonFactory->create();
                 return $resultJson->setData(['errors' => true, 'message' => __('Incorrect CAPTCHA')]);
             }
         }
     }
     return $proceed();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:40,代码来源:AjaxLogin.php

示例2: execute

 /**
  * Check captcha on user login page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @throws NoSuchEntityException
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'user_login';
     $captchaModel = $this->_helper->getCaptcha($formId);
     $controller = $observer->getControllerAction();
     $loginParams = $controller->getRequest()->getPost('login');
     $login = is_array($loginParams) && array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
     if ($captchaModel->isRequired($login)) {
         $word = $this->captchaStringResolver->resolve($controller->getRequest(), $formId);
         if (!$captchaModel->isCorrect($word)) {
             try {
                 $customer = $this->getCustomerRepository()->get($login);
                 $this->getAuthentication()->processAuthenticationFailure($customer->getId());
             } catch (NoSuchEntityException $e) {
                 //do nothing as customer existance is validated later in authenticate method
             }
             $this->messageManager->addError(__('Incorrect CAPTCHA'));
             $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->_session->setUsername($login);
             $beforeUrl = $this->_session->getBeforeAuthUrl();
             $url = $beforeUrl ? $beforeUrl : $this->_customerUrl->getLoginUrl();
             $controller->getResponse()->setRedirect($url);
         }
     }
     $captchaModel->logAttempt($login);
     return $this;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:34,代码来源:CheckUserLoginObserver.php

示例3: execute

 /**
  * Check Captcha On User Login Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $formId = 'user_login';
     $captchaModel = $this->_helper->getCaptcha($formId);
     $controller = $observer->getControllerAction();
     $loginParams = $controller->getRequest()->getPost('login');
     $login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
     if ($captchaModel->isRequired($login)) {
         $word = $this->captchaStringResolver->resolve($controller->getRequest(), $formId);
         if (!$captchaModel->isCorrect($word)) {
             $this->messageManager->addError(__('Incorrect CAPTCHA'));
             $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->_session->setUsername($login);
             $beforeUrl = $this->_session->getBeforeAuthUrl();
             $url = $beforeUrl ? $beforeUrl : $this->_customerUrl->getLoginUrl();
             $controller->getResponse()->setRedirect($url);
         }
     }
     $captchaModel->logAttempt($login);
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:27,代码来源:CheckUserLoginObserver.php

示例4: aroundExecute

 /**
  * @param \Magento\Customer\Controller\Ajax\Login $subject
  * @param callable $proceed
  * @return \Magento\Framework\Controller\ResultInterface
  * @throws \Zend_Json_Exception
  */
 public function aroundExecute(\Magento\Customer\Controller\Ajax\Login $subject, \Closure $proceed)
 {
     $loginFormId = 'user_login';
     $captchaInputName = 'captcha_string';
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $subject->getRequest();
     /** @var \Magento\Captcha\Model\ModelInterface $captchaModel */
     $captchaModel = $this->helper->getCaptcha($loginFormId);
     $loginParams = \Zend_Json::decode($request->getContent());
     $username = isset($loginParams['username']) ? $loginParams['username'] : null;
     $captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
     if ($captchaModel->isRequired($username)) {
         $captchaModel->logAttempt($username);
         if (!$captchaModel->isCorrect($captchaString)) {
             $this->sessionManager->setUsername($username);
             /** @var \Magento\Framework\Controller\Result\Json $resultJson */
             $resultJson = $this->resultJsonFactory->create();
             return $resultJson->setData(['errors' => true, 'message' => __('Incorrect CAPTCHA')]);
         }
     }
     return $proceed();
 }
开发者ID:kid17,项目名称:magento2,代码行数:28,代码来源:AjaxLogin.php


注:本文中的Magento\Framework\Session\SessionManagerInterface::setUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。