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


PHP Api\AccountManagementInterface类代码示例

本文整理汇总了PHP中Magento\Customer\Api\AccountManagementInterface的典型用法代码示例。如果您正苦于以下问题:PHP AccountManagementInterface类的具体用法?PHP AccountManagementInterface怎么用?PHP AccountManagementInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AccountManagementInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: executeInternal

 /**
  * Resetting password handler
  *
  * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
  */
 public function executeInternal()
 {
     $resetPasswordToken = (string) $this->getRequest()->getParam('token');
     $customerId = (int) $this->getRequest()->getParam('id');
     $isDirectLink = $resetPasswordToken != '' && $customerId != 0;
     if (!$isDirectLink) {
         $resetPasswordToken = (string) $this->session->getRpToken();
         $customerId = (int) $this->session->getRpCustomerId();
     }
     try {
         $this->accountManagement->validateResetPasswordLinkToken($customerId, $resetPasswordToken);
         if ($isDirectLink) {
             $this->session->setRpToken($resetPasswordToken);
             $this->session->setRpCustomerId($customerId);
             $resultRedirect = $this->resultRedirectFactory->create();
             $resultRedirect->setPath('*/*/createpassword');
             return $resultRedirect;
         } else {
             /** @var \Magento\Framework\View\Result\Page $resultPage */
             $resultPage = $this->resultPageFactory->create();
             $resultPage->getLayout()->getBlock('resetPassword')->setCustomerId($customerId)->setResetPasswordLinkToken($resetPasswordToken);
             return $resultPage;
         }
     } catch (\Exception $exception) {
         $this->messageManager->addError(__('Your password reset link has expired.'));
         /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('*/*/forgotpassword');
         return $resultRedirect;
     }
 }
开发者ID:nblair,项目名称:magescotch,代码行数:36,代码来源:CreatePassword.php

示例3: execute

 /**
  * Forgot customer password action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     $email = (string) $this->getRequest()->getPost('email');
     if ($email) {
         if (!\Zend_Validate::is($email, 'EmailAddress')) {
             $this->session->setForgottenEmail($email);
             $this->messageManager->addErrorMessage(__('Please correct the email address.'));
             return $resultRedirect->setPath('*/*/forgotpassword');
         }
         try {
             $this->customerAccountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET);
         } catch (NoSuchEntityException $exception) {
             // Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
         } catch (SecurityViolationException $exception) {
             $this->messageManager->addErrorMessage($exception->getMessage());
             return $resultRedirect->setPath('*/*/forgotpassword');
         } catch (\Exception $exception) {
             $this->messageManager->addExceptionMessage($exception, __('We\'re unable to send the password reset email.'));
             return $resultRedirect->setPath('*/*/forgotpassword');
         }
         $this->messageManager->addSuccessMessage($this->getSuccessMessage($email));
         return $resultRedirect->setPath('*/*/');
     } else {
         $this->messageManager->addErrorMessage(__('Please enter your email.'));
         return $resultRedirect->setPath('*/*/forgotpassword');
     }
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:34,代码来源:ForgotPasswordPost.php

示例4: execute

 /**
  * Login post action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     if ($this->_getSession()->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->_getSession()->setCustomerDataAsLoggedIn($customer);
                 $this->_getSession()->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->_getSession()->setUsername($login['username']);
             } catch (AuthenticationException $e) {
                 $message = __('Invalid login or password.');
                 $this->messageManager->addError($message);
                 $this->_getSession()->setUsername($login['username']);
             } catch (\Exception $e) {
                 $this->messageManager->addError(__('There was an error validating the login and password.'));
             }
         } else {
             $this->messageManager->addError(__('Login and password are required.'));
         }
     }
     return $this->accountRedirect->getRedirect();
 }
开发者ID:opexsw,项目名称:magento2,代码行数:39,代码来源:LoginPost.php

示例5: validateEmailAvailable

 /**
  * Validates that the email address isn't being used by a different account.
  *
  * @param string $email
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return void
  */
 protected function validateEmailAvailable($email)
 {
     $websiteId = $this->_storeManager->getStore()->getWebsiteId();
     if ($this->_customerSession->getCustomerDataObject()->getEmail() !== $email && !$this->customerAccountManagement->isEmailAvailable($email, $websiteId)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('This email address is already assigned to another user.'));
     }
 }
开发者ID:nblair,项目名称:magescotch,代码行数:14,代码来源:NewAction.php

示例6: execute

 /**
  * Login registered users and initiate a session.
  *
  * Expects a POST. ex for JSON {"username":"user@magento.com", "password":"userpassword"}
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $credentials = null;
     $httpBadRequestCode = 400;
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     try {
         $credentials = $this->helper->jsonDecode($this->getRequest()->getContent());
     } catch (\Exception $e) {
         return $resultRaw->setHttpResponseCode($httpBadRequestCode);
     }
     if (!$credentials || $this->getRequest()->getMethod() !== 'POST' || !$this->getRequest()->isXmlHttpRequest()) {
         return $resultRaw->setHttpResponseCode($httpBadRequestCode);
     }
     $response = ['errors' => false, 'message' => __('Login successful.')];
     try {
         $customer = $this->customerAccountManagement->authenticate($credentials['username'], $credentials['password']);
         $this->customerSession->setCustomerDataAsLoggedIn($customer);
         $this->customerSession->regenerateId();
     } catch (EmailNotConfirmedException $e) {
         $response = ['errors' => true, 'message' => $e->getMessage()];
     } catch (InvalidEmailOrPasswordException $e) {
         $response = ['errors' => true, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $response = ['errors' => true, 'message' => __('Something went wrong while validating the login and password.')];
     }
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData($response);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:37,代码来源:Login.php

示例7: execute

 /**
  * Forgot customer password action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     $email = (string) $this->getRequest()->getPost('email');
     if ($email) {
         if (!\Zend_Validate::is($email, 'EmailAddress')) {
             $this->_getSession()->setForgottenEmail($email);
             $this->messageManager->addError(__('Please correct the email address.'));
             $resultRedirect->setPath('*/*/forgotpassword');
             return $resultRedirect;
         }
         try {
             $this->customerAccountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET);
         } catch (NoSuchEntityException $e) {
             // Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
         } catch (\Exception $exception) {
             $this->messageManager->addException($exception, __('Unable to send password reset email.'));
             $resultRedirect->setPath('*/*/forgotpassword');
             return $resultRedirect;
         }
         $email = $this->escaper->escapeHtml($email);
         // @codingStandardsIgnoreStart
         $this->messageManager->addSuccess(__('If there is an account associated with %1 you will receive an email with a link to reset your password.', $email));
         // @codingStandardsIgnoreEnd
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     } else {
         $this->messageManager->addError(__('Please enter your email.'));
         $resultRedirect->setPath('*/*/forgotpassword');
         return $resultRedirect;
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:38,代码来源:ForgotPasswordPost.php

示例8: create

 /**
  * {@inheritdoc}
  */
 public function create($orderId)
 {
     $order = $this->orderRepository->get($orderId);
     if ($order->getCustomerId()) {
         throw new AlreadyExistsException(__("This order already has associated customer account"));
     }
     $customerData = $this->objectCopyService->copyFieldsetToTarget('order_address', 'to_customer', $order->getBillingAddress(), []);
     $addresses = $order->getAddresses();
     foreach ($addresses as $address) {
         $addressData = $this->objectCopyService->copyFieldsetToTarget('order_address', 'to_customer_address', $address, []);
         /** @var \Magento\Customer\Api\Data\AddressInterface $customerAddress */
         $customerAddress = $this->addressFactory->create(['data' => $addressData]);
         if (is_string($address->getRegion())) {
             /** @var \Magento\Customer\Api\Data\RegionInterface $region */
             $region = $this->regionFactory->create();
             $region->setRegion($address->getRegion());
             $region->setRegionCode($address->getRegionCode());
             $region->setRegionId($address->getRegionId());
             $customerAddress->setRegion($region);
         }
         $customerData['addresses'][] = $customerAddress;
     }
     /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
     $customer = $this->customerFactory->create(['data' => $customerData]);
     $account = $this->accountManagement->createAccount($customer);
     $order->setCustomerId($account->getId());
     $this->orderRepository->save($order);
     return $account;
 }
开发者ID:nja78,项目名称:magento2,代码行数:32,代码来源:Management.php

示例9: execute

 /**
  * Confirm customer account by id and confirmation key
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     if ($this->_getSession()->isLoggedIn()) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     try {
         $customerId = $this->getRequest()->getParam('id', false);
         $key = $this->getRequest()->getParam('key', false);
         if (empty($customerId) || empty($key)) {
             throw new \Exception(__('Bad request.'));
         }
         // log in and send greeting email
         $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
         $customer = $this->customerAccountManagement->activate($customerEmail, $key);
         $this->_getSession()->setCustomerDataAsLoggedIn($customer);
         $this->messageManager->addSuccess($this->getSuccessMessage());
         $resultRedirect->setUrl($this->getSuccessRedirect());
         return $resultRedirect;
     } catch (StateException $e) {
         $this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('There was an error confirming the account'));
     }
     $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
     return $resultRedirect->setUrl($this->_redirect->error($url));
 }
开发者ID:nja78,项目名称:magento2,代码行数:34,代码来源:Confirm.php

示例10: execute

 /**
  * Reset forgotten password
  *
  * Used to handle data received from reset forgotten password form
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     $resetPasswordToken = (string) $this->getRequest()->getQuery('token');
     $customerId = (int) $this->getRequest()->getQuery('id');
     $password = (string) $this->getRequest()->getPost('password');
     $passwordConfirmation = (string) $this->getRequest()->getPost('password_confirmation');
     if ($password !== $passwordConfirmation) {
         $this->messageManager->addError(__("New Password and Confirm New Password values didn't match."));
         $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
         return $resultRedirect;
     }
     if (iconv_strlen($password) <= 0) {
         $this->messageManager->addError(__('New password field cannot be empty.'));
         $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
         return $resultRedirect;
     }
     try {
         $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
         $this->accountManagement->resetPassword($customerEmail, $resetPasswordToken, $password);
         $this->messageManager->addSuccess(__('Your password has been updated.'));
         $resultRedirect->setPath('*/*/login');
         return $resultRedirect;
     } catch (\Exception $exception) {
         $this->messageManager->addError(__('There was an error saving the new password.'));
         $resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
         return $resultRedirect;
     }
 }
开发者ID:opexsw,项目名称:magento2,代码行数:37,代码来源:ResetPasswordPost.php

示例11: toHtml

 /**
  * {@inheritdoc}
  */
 public function toHtml()
 {
     if ($this->customerSession->isLoggedIn() || !$this->registration->isAllowed() || !$this->accountManagement->isEmailAvailable($this->getEmailAddress()) || !$this->validateAddresses()) {
         return '';
     }
     return parent::toHtml();
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:Registration.php

示例12: execute

 /**
  * Change customer password action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if (!$this->formKeyValidator->validate($this->getRequest())) {
         $resultRedirect->setPath('*/*/edit');
         return $resultRedirect;
     }
     if ($this->getRequest()->isPost()) {
         $customerId = $this->_getSession()->getCustomerId();
         $customer = $this->customerExtractor->extract('customer_account_edit', $this->_request);
         $customer->setId($customerId);
         if ($customer->getAddresses() == null) {
             $customer->setAddresses($this->customerRepository->getById($customerId)->getAddresses());
         }
         if ($this->getRequest()->getParam('change_password')) {
             $currPass = $this->getRequest()->getPost('current_password');
             $newPass = $this->getRequest()->getPost('password');
             $confPass = $this->getRequest()->getPost('password_confirmation');
             if (strlen($newPass)) {
                 if ($newPass == $confPass) {
                     try {
                         $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
                         $this->customerAccountManagement->changePassword($customerEmail, $currPass, $newPass);
                     } catch (AuthenticationException $e) {
                         $this->messageManager->addError($e->getMessage());
                     } catch (\Exception $e) {
                         $this->messageManager->addException($e, __('Something went wrong while changing the password.'));
                     }
                 } else {
                     $this->messageManager->addError(__('Confirm your new password.'));
                 }
             } else {
                 $this->messageManager->addError(__('Please enter new password.'));
             }
         }
         try {
             $this->customerRepository->save($customer);
         } catch (AuthenticationException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (InputException $e) {
             $this->messageManager->addException($e, __('Invalid input'));
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('We can\'t save the customer.') . $e->getMessage() . '<pre>' . $e->getTraceAsString() . '</pre>');
         }
         if ($this->messageManager->getMessages()->getCount() > 0) {
             $this->_getSession()->setCustomerFormData($this->getRequest()->getPostValue());
             $resultRedirect->setPath('*/*/edit');
             return $resultRedirect;
         }
         $this->messageManager->addSuccess(__('You saved the account information.'));
         $resultRedirect->setPath('customer/account');
         return $resultRedirect;
     }
     $resultRedirect->setPath('*/*/edit');
     return $resultRedirect;
 }
开发者ID:nja78,项目名称:magento2,代码行数:63,代码来源:EditPost.php

示例13: testCustomerCreatedNotSubscribed

 /**
  * @magentoAppArea adminhtml
  * @magentoDbIsolation enabled
  */
 public function testCustomerCreatedNotSubscribed()
 {
     $this->verifySubscriptionNotExist('customer@example.com');
     $objectManager = Bootstrap::getObjectManager();
     /** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
     $customerFactory = $objectManager->get('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory');
     $customerDataObject = $customerFactory->create()->setFirstname('Firstname')->setLastname('Lastname')->setEmail('customer@example.com');
     $this->accountManagement->createAccount($customerDataObject);
     $this->verifySubscriptionNotExist('customer@example.com');
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:PluginTest.php

示例14: getButtonData

 /**
  * @return array
  */
 public function getButtonData()
 {
     $customerId = $this->getCustomerId();
     $canModify = $customerId && !$this->customerAccountManagement->isReadonly($this->getCustomerId());
     $data = [];
     if ($customerId && $canModify) {
         $data = ['label' => __('Delete Customer'), 'class' => 'delete', 'id' => 'customer-edit-delete-button', 'data_attribute' => ['url' => $this->getDeleteUrl()], 'on_click' => '', 'sort_order' => 20];
     }
     return $data;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:13,代码来源:DeleteButton.php

示例15: getButtonData

 /**
  * @return array
  */
 public function getButtonData()
 {
     $customerId = $this->getCustomerId();
     $canModify = !$customerId || !$this->customerAccountManagement->isReadonly($this->getCustomerId());
     $data = [];
     if ($canModify) {
         $data = ['label' => __('Save and Continue Edit'), 'class' => 'save', 'data_attribute' => ['mage-init' => ['button' => ['event' => 'saveAndContinueEdit']]], 'sort_order' => 80];
     }
     return $data;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:13,代码来源:SaveAndContinueButton.php


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