本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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();
}