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


PHP Session::setUsername方法代码示例

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


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

示例1: execute

 /**
  * Send confirmation link to specified email
  *
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     if ($this->session->isLoggedIn()) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     // try to confirm by email
     $email = $this->getRequest()->getPost('email');
     if ($email) {
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         try {
             $this->customerAccountManagement->resendConfirmation($email, $this->storeManager->getStore()->getWebsiteId());
             $this->messageManager->addSuccess(__('Please check your email for confirmation key.'));
         } catch (InvalidTransitionException $e) {
             $this->messageManager->addSuccess(__('This email does not require confirmation.'));
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('Wrong email.'));
             $resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]);
             return $resultRedirect;
         }
         $this->session->setUsername($email);
         $resultRedirect->setPath('*/*/index', ['_secure' => true]);
         return $resultRedirect;
     }
     /** @var \Magento\Framework\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->getLayout()->getBlock('accountConfirmation')->setEmail($this->getRequest()->getParam('email', $email));
     return $resultPage;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:37,代码来源:Confirmation.php

示例2: 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

示例3: 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


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