本文整理匯總了PHP中Magento\Customer\Model\Session::start方法的典型用法代碼示例。如果您正苦於以下問題:PHP Session::start方法的具體用法?PHP Session::start怎麽用?PHP Session::start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Customer\Model\Session
的用法示例。
在下文中一共展示了Session::start方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
/**
* Check Captcha On Forgot Password Page
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$captchaModel = $this->helper->getCaptcha(self::FORM_ID);
if ($captchaModel->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) {
$customerId = $this->customerSession->getCustomerId();
$this->authentication->processAuthenticationFailure($customerId);
if ($this->authentication->isLocked($customerId)) {
$this->customerSession->logout();
$this->customerSession->start();
$message = __('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email'));
$this->messageManager->addError($message);
}
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), '*/*/edit');
}
}
$customer = $this->customerSession->getCustomer();
$login = $customer->getEmail();
$captchaModel->logAttempt($login);
return $this;
}
示例2: execute
/**
* Change customer email or password action
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
if (!$this->formKeyValidator->validate($this->getRequest())) {
return $resultRedirect->setPath('*/*/edit');
}
if ($this->getRequest()->isPost()) {
$currentCustomerDataObject = $this->getCurrentCustomerDataObject();
$customerCandidateDataObject = $this->populateNewCustomerDataObject($this->_request, $currentCustomerDataObject);
try {
// whether a customer enabled change email option
$this->changeEmail($currentCustomerDataObject);
// whether a customer enabled change password option
$isPasswordChanged = $this->changePassword($currentCustomerDataObject);
$this->customerRepository->save($customerCandidateDataObject);
$this->getEmailNotification()->sendNotificationEmailsIfRequired($currentCustomerDataObject, $customerCandidateDataObject, $isPasswordChanged);
$this->dispatchSuccessEvent($customerCandidateDataObject);
$this->messageManager->addSuccess(__('You saved the account information.'));
return $resultRedirect->setPath('customer/account');
} catch (InvalidEmailOrPasswordException $e) {
$this->messageManager->addError($e->getMessage());
} catch (UserLockedException $e) {
$this->session->logout();
$this->session->start();
$this->messageManager->addError($e->getMessage());
return $resultRedirect->setPath('customer/account/login');
} catch (InputException $e) {
$this->messageManager->addError($e->getMessage());
foreach ($e->getErrors() as $error) {
$this->messageManager->addError($error->getMessage());
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t save the customer.'));
}
$this->session->setCustomerFormData($this->getRequest()->getPostValue());
return $resultRedirect->setPath('*/*/edit');
}
return $resultRedirect->setPath('*/*/edit');
}