當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。