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


PHP Session::regenerateId方法代码示例

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


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

示例1: execute

 /**
  * Login post action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     if ($this->session->isLoggedIn() || !$this->formKeyValidator->validate($this->getRequest())) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     if ($this->getRequest()->isPost()) {
         $login = $this->getRequest()->getPost('login');
         if (!empty($login['username']) && !empty($login['password'])) {
             try {
                 $customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
                 $this->session->setCustomerDataAsLoggedIn($customer);
                 $this->session->regenerateId();
             } catch (EmailNotConfirmedException $e) {
                 $value = $this->customerUrl->getEmailConfirmationUrl($login['username']);
                 $message = __('This account is not confirmed.' . ' <a href="%1">Click here</a> to resend confirmation email.', $value);
                 $this->messageManager->addError($message);
                 $this->session->setUsername($login['username']);
             } catch (AuthenticationException $e) {
                 $message = __('Invalid login or password.');
                 $this->messageManager->addError($message);
                 $this->session->setUsername($login['username']);
             } catch (\Exception $e) {
                 $this->messageManager->addError(__('Invalid login or password.'));
             }
         } else {
             $this->messageManager->addError(__('A login and a password are required.'));
         }
     }
     return $this->accountRedirect->getRedirect();
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:39,代码来源:LoginPost.php

示例2: beforeDispatch

 /**
  * @param AbstractAction $subject
  * @param RequestInterface $request
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
 {
     if ($this->state->getAreaCode() == Area::AREA_FRONTEND && $request->isPost() && $this->notificationStorage->isExists(NotificationStorage::UPDATE_CUSTOMER_SESSION, $this->session->getCustomerId())) {
         $customer = $this->customerRepository->getById($this->session->getCustomerId());
         $this->session->setCustomerData($customer);
         $this->session->setCustomerGroupId($customer->getGroupId());
         $this->session->regenerateId();
         $this->notificationStorage->remove(NotificationStorage::UPDATE_CUSTOMER_SESSION, $customer->getId());
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:CustomerNotification.php

示例3: auth

 /**
  * @return bool
  */
 protected function auth()
 {
     if (!$this->customerSession->isLoggedIn()) {
         list($login, $password) = $this->httpAuthentication->getCredentials();
         try {
             $customer = $this->customerAccountManagement->authenticate($login, $password);
             $this->customerSession->setCustomerDataAsLoggedIn($customer);
             $this->customerSession->regenerateId();
         } catch (\Exception $e) {
             $this->logger->critical($e);
         }
     }
     if (!$this->customerSession->isLoggedIn()) {
         $this->httpAuthentication->setAuthenticationFailed('RSS Feeds');
         return false;
     }
     return true;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:21,代码来源:Feed.php

示例4: execute

 /**
  * Login post action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     if ($this->session->isLoggedIn() || !$this->formKeyValidator->validate($this->getRequest())) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     if ($this->getRequest()->isPost()) {
         $login = $this->getRequest()->getPost('login');
         if (!empty($login['username']) && !empty($login['password'])) {
             try {
                 $customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
                 $this->session->setCustomerDataAsLoggedIn($customer);
                 $this->session->regenerateId();
                 if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
                     $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
                     $metadata->setPath('/');
                     $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
                 }
                 $redirectUrl = $this->accountRedirect->getRedirectCookie();
                 if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectUrl) {
                     $this->accountRedirect->clearRedirectCookie();
                     $resultRedirect = $this->resultRedirectFactory->create();
                     // URL is checked to be internal in $this->_redirect->success()
                     $resultRedirect->setUrl($this->_redirect->success($redirectUrl));
                     return $resultRedirect;
                 }
             } catch (EmailNotConfirmedException $e) {
                 $value = $this->customerUrl->getEmailConfirmationUrl($login['username']);
                 $message = __('This account is not confirmed. <a href="%1">Click here</a> to resend confirmation email.', $value);
                 $this->messageManager->addError($message);
                 $this->session->setUsername($login['username']);
             } catch (UserLockedException $e) {
                 $message = __('The account is locked. Please wait and try again or contact %1.', $this->getScopeConfig()->getValue('contact/email/recipient_email'));
                 $this->messageManager->addError($message);
                 $this->session->setUsername($login['username']);
             } catch (AuthenticationException $e) {
                 $message = __('Invalid login or password.');
                 $this->messageManager->addError($message);
                 $this->session->setUsername($login['username']);
             } catch (LocalizedException $e) {
                 $message = $e->getMessage();
                 $this->messageManager->addError($message);
                 $this->session->setUsername($login['username']);
             } catch (\Exception $e) {
                 // PA DSS violation: throwing or logging an exception here can disclose customer password
                 $this->messageManager->addError(__('An unspecified error occurred. Please contact us for assistance.'));
             }
         } else {
             $this->messageManager->addError(__('A login and a password are required.'));
         }
     }
     return $this->accountRedirect->getRedirect();
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:61,代码来源:LoginPost.php

示例5: authenticateCustomer

 /**
  * Login Customer
  * @return false || \Magento\Customer\Model\Customer
  */
 public function authenticateCustomer()
 {
     $customer = $this->getCustomer();
     if (!$customer->getId()) {
         throw new \Exception(__("Customer are no longer exist."), 1);
     }
     if ($this->_customerSession->loginById($customer->getId())) {
         $this->_customerSession->regenerateId();
         $this->_customerSession->setLoggedAsCustomerAdmindId($this->getAdminId());
     }
     $this->setUsed(1)->save();
     return $customer;
 }
开发者ID:magefan,项目名称:module-login-as-customer,代码行数:17,代码来源:Login.php

示例6: execute

 /**
  * Create customer account action
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($this->session->isLoggedIn() || !$this->registration->isAllowed()) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     if (!$this->getRequest()->isPost()) {
         $url = $this->urlModel->getUrl('*/*/create', ['_secure' => true]);
         $resultRedirect->setUrl($this->_redirect->error($url));
         return $resultRedirect;
     }
     $this->session->regenerateId();
     try {
         $address = $this->extractAddress();
         $addresses = $address === null ? [] : [$address];
         $customer = $this->customerExtractor->extract('customer_account_create', $this->_request);
         $customer->setAddresses($addresses);
         $password = $this->getRequest()->getParam('password');
         $confirmation = $this->getRequest()->getParam('password_confirmation');
         $redirectUrl = $this->session->getBeforeAuthUrl();
         $this->checkPasswordConfirmation($password, $confirmation);
         $customer = $this->accountManagement->createAccount($customer, $password, $redirectUrl);
         if ($this->getRequest()->getParam('is_subscribed', false)) {
             $this->subscriberFactory->create()->subscribeCustomerById($customer->getId());
         }
         $this->_eventManager->dispatch('customer_register_success', ['account_controller' => $this, 'customer' => $customer]);
         $confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId());
         if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
             $email = $this->customerUrl->getEmailConfirmationUrl($customer->getEmail());
             // @codingStandardsIgnoreStart
             $this->messageManager->addSuccess(__('You must confirm your account. Please check your email for the confirmation link or <a href="%1">click here</a> for a new link.', $email));
             // @codingStandardsIgnoreEnd
             $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
             $resultRedirect->setUrl($this->_redirect->success($url));
         } else {
             $this->session->setCustomerDataAsLoggedIn($customer);
             $this->messageManager->addSuccess($this->getSuccessMessage());
             $resultRedirect = $this->accountRedirect->getRedirect();
         }
         return $resultRedirect;
     } catch (StateException $e) {
         $url = $this->urlModel->getUrl('customer/account/forgotpassword');
         // @codingStandardsIgnoreStart
         $message = __('There is already an account with this email address. If you are sure that it is your email address, <a href="%1">click here</a> to get your password and access your account.', $url);
         // @codingStandardsIgnoreEnd
         $this->messageManager->addError($message);
     } catch (InputException $e) {
         $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage()));
         foreach ($e->getErrors() as $error) {
             $this->messageManager->addError($this->escaper->escapeHtml($error->getMessage()));
         }
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('We can\'t save the customer.'));
     }
     $this->session->setCustomerFormData($this->getRequest()->getPostValue());
     $defaultUrl = $this->urlModel->getUrl('*/*/create', ['_secure' => true]);
     $resultRedirect->setUrl($this->_redirect->error($defaultUrl));
     return $resultRedirect;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:67,代码来源:CreatePost.php

示例7: login

 /**
  * Authorization customer by id
  *
  * @param int $customerId
  */
 private function login($customerId)
 {
     $this->customerSession->loginById($customerId);
     $this->customerSession->regenerateId();
 }
开发者ID:Viktor-V,项目名称:Facebook-Login,代码行数:10,代码来源:Index.php


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