/** * Change customer password action * * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { if (!$this->_formKeyValidator->validate($this->getRequest())) { $this->_redirect('*/*/edit'); return; } if ($this->getRequest()->isPost()) { $customerId = $this->_getSession()->getCustomerId(); $customer = $this->customerExtractor->extract('customer_account_edit', $this->_request); $this->_customerBuilder->populate($customer); $this->_customerBuilder->setId($customerId); $customer = $this->_customerBuilder->create(); if ($this->getRequest()->getParam('change_password')) { $currPass = $this->getRequest()->getPost('current_password'); $newPass = $this->getRequest()->getPost('password'); $confPass = $this->getRequest()->getPost('confirmation'); if (strlen($newPass)) { if ($newPass == $confPass) { try { $this->_customerAccountService->changePassword($customerId, $currPass, $newPass); } catch (AuthenticationException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('A problem was encountered trying to change password.')); } } else { $this->messageManager->addError(__('Confirm your new password')); } } else { $this->messageManager->addError(__('New password field cannot be empty.')); } } try { $this->_customerDetailsBuilder->setCustomer($customer); $this->_customerAccountService->updateCustomer($this->_customerDetailsBuilder->create()); } catch (AuthenticationException $e) { $this->messageManager->addError($e->getMessage()); } catch (InputException $e) { $this->messageManager->addException($e, __('Invalid input')); } catch (\Exception $e) { $this->messageManager->addException($e, __('Cannot save the customer.') . $e->getMessage() . '<pre>' . $e->getTraceAsString() . '</pre>'); } if ($this->messageManager->getMessages()->getCount() > 0) { $this->_getSession()->setCustomerFormData($this->getRequest()->getPost()); $this->_redirect('*/*/edit'); return; } $this->messageManager->addSuccess(__('The account information has been saved.')); $this->_redirect('customer/account'); return; } $this->_redirect('*/*/edit'); }
/** * Overview action * * @return void */ public function execute() { if (!$this->formKeyValidator->validate($this->getRequest())) { $this->_forward('backToAddresses'); return; } if (!$this->_validateMinimumAmount()) { return; } try { $agreementsValidator = $this->_objectManager->get('Magento\\Checkout\\Model\\Agreements\\AgreementsValidator'); if (!$agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', array())))) { $this->messageManager->addError(__('Please agree to all Terms and Conditions before placing the order.')); $this->_redirect('*/*/billing'); return; } $payment = $this->getRequest()->getPost('payment'); $paymentInstance = $this->_getCheckout()->getQuote()->getPayment(); if (isset($payment['cc_number'])) { $paymentInstance->setCcNumber($payment['cc_number']); } if (isset($payment['cc_cid'])) { $paymentInstance->setCcCid($payment['cc_cid']); } $this->_getCheckout()->createOrders(); $this->_getState()->setActiveStep(State::STEP_SUCCESS); $this->_getState()->setCompleteStep(State::STEP_OVERVIEW); $this->_getCheckout()->getCheckoutSession()->clearQuote(); $this->_getCheckout()->getCheckoutSession()->setDisplaySuccess(true); $this->_redirect('*/*/success'); } catch (\Magento\Payment\Model\Info\Exception $e) { $message = $e->getMessage(); if (!empty($message)) { $this->messageManager->addError($message); } $this->_redirect('*/*/billing'); } catch (\Magento\Checkout\Exception $e) { $this->_objectManager->get('Magento\\Checkout\\Helper\\Data')->sendPaymentFailedEmail($this->_getCheckout()->getQuote(), $e->getMessage(), 'multi-shipping'); $this->_getCheckout()->getCheckoutSession()->clearQuote(); $this->messageManager->addError($e->getMessage()); $this->_redirect('*/cart'); } catch (\Magento\Framework\Model\Exception $e) { $this->_objectManager->get('Magento\\Checkout\\Helper\\Data')->sendPaymentFailedEmail($this->_getCheckout()->getQuote(), $e->getMessage(), 'multi-shipping'); $this->messageManager->addError($e->getMessage()); $this->_redirect('*/*/billing'); } catch (\Exception $e) { $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); $this->_objectManager->get('Magento\\Checkout\\Helper\\Data')->sendPaymentFailedEmail($this->_getCheckout()->getQuote(), $e->getMessage(), 'multi-shipping'); $this->messageManager->addError(__('Order place error')); $this->_redirect('*/*/billing'); } }
/** * Add all items from wishlist to shopping cart * * @return void */ public function execute() { if (!$this->formKeyValidator->validate($this->getRequest())) { $this->_forward('noroute'); return; } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { $this->_forward('noroute'); return; } $redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty')); $this->getResponse()->setRedirect($redirectUrl); }
/** * Check url keys. If non valid - redirect * * @return bool */ public function _processUrlKeys() { $_isValidFormKey = true; $_isValidSecretKey = true; $_keyErrorMsg = ''; if ($this->_auth->isLoggedIn()) { if ($this->getRequest()->isPost()) { $_isValidFormKey = $this->_formKeyValidator->validate($this->getRequest()); $_keyErrorMsg = __('Invalid Form Key. Please refresh the page.'); } elseif ($this->_backendUrl->useSecretKey()) { $_isValidSecretKey = $this->_validateSecretKey(); $_keyErrorMsg = __('You entered an invalid Secret Key. Please refresh the page.'); } } if (!$_isValidFormKey || !$_isValidSecretKey) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); $this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true); if ($this->getRequest()->getQuery('isAjax', false) || $this->getRequest()->getQuery('ajax', false)) { $this->getResponse()->representJson($this->_objectManager->get('Magento\\Core\\Helper\\Data')->jsonEncode(array('error' => true, 'message' => $_keyErrorMsg))); } else { $this->_redirect($this->_backendUrl->getStartupPageUrl()); } return false; } return true; }
/** * Login post action * * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { if ($this->_getSession()->isLoggedIn() || !$this->_formKeyValidator->validate($this->getRequest())) { $this->_redirect('*/*/'); return; } if ($this->getRequest()->isPost()) { $login = $this->getRequest()->getPost('login'); if (!empty($login['username']) && !empty($login['password'])) { try { $customer = $this->_customerAccountService->authenticate($login['username'], $login['password']); $this->_getSession()->setCustomerDataAsLoggedIn($customer); $this->_getSession()->regenerateId(); } catch (EmailNotConfirmedException $e) { $value = $this->_customerHelperData->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) { // PA DSS violation: this exception log can disclose customer password // $this->_objectManager->get('Magento\Framework\Logger')->logException($e); $this->messageManager->addError(__('There was an error validating the login and password.')); } } else { $this->messageManager->addError(__('Login and password are required.')); } } $this->_loginPostRedirect(); }
/** * @param string $formKey * @param bool $expected * @dataProvider validateDataProvider */ public function testValidate($formKey, $expected) { $this->_requestMock->expects($this->once())->method('getParam')->with('form_key', null)->will($this->returnValue($formKey)); $this->_formKeyMock->expects($this->once())->method('getFormKey')->will($this->returnValue('formKey')); $this->assertEquals($expected, $this->_model->validate($this->_requestMock)); }
/** * Share wishlist * * @return ResponseInterface|void * @throws NotFoundException */ public function execute() { if (!$this->_formKeyValidator->validate($this->getRequest())) { return $this->_redirect('*/*/'); } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(); } $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit(); $textLimit = $this->_wishlistConfig->getSharingTextLimit(); $emailsLeft = $sharingLimit - $wishlist->getShared(); $emails = explode(',', $this->getRequest()->getPost('emails')); $error = false; $message = (string) $this->getRequest()->getPost('message'); if (strlen($message) > $textLimit) { $error = __('Message length must not exceed %1 symbols', $textLimit); } else { $message = nl2br(htmlspecialchars($message)); if (empty($emails)) { $error = __('Email address can\'t be empty.'); } else { if (count($emails) > $emailsLeft) { $error = __('This wishlist can be shared %1 more times.', $emailsLeft); } else { foreach ($emails as $index => $email) { $email = trim($email); if (!\Zend_Validate::is($email, 'EmailAddress')) { $error = __('Please input a valid email address.'); break; } $emails[$index] = $email; } } } } if ($error) { $this->messageManager->addError($error); $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); return; } $this->inlineTranslation->suspend(); $sent = 0; try { $customer = $this->_customerSession->getCustomerDataObject(); $customerName = $this->_customerHelperView->getCustomerName($customer); /*if share rss added rss feed to email template*/ if ($this->getRequest()->getParam('rss_url')) { $rss_url = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Rss')->setWishlistId($wishlist->getId())->toHtml(); $message .= $rss_url; } $wishlistBlock = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Items')->toHtml(); $emails = array_unique($emails); $sharingCode = $wishlist->getSharingCode(); try { $scopeConfig = $this->_objectManager->get('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $storeManager = $this->_objectManager->get('Magento\\Framework\\StoreManagerInterface'); foreach ($emails as $email) { $transport = $this->_transportBuilder->setTemplateIdentifier($scopeConfig->getValue('wishlist/email/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeManager->getStore()->getStoreId()))->setTemplateVars(array('customer' => $customer, 'customerName' => $customerName, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => $wishlistBlock, 'addAllLink' => $this->_url->getUrl('*/shared/allcart', array('code' => $sharingCode)), 'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', array('code' => $sharingCode)), 'message' => $message, 'store' => $storeManager->getStore()))->setFrom($scopeConfig->getValue('wishlist/email/email_identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($email)->getTransport(); $transport->sendMessage(); $sent++; } } catch (\Exception $e) { $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); throw $e; } $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); $this->inlineTranslation->resume(); $this->_eventManager->dispatch('wishlist_share', array('wishlist' => $wishlist)); $this->messageManager->addSuccess(__('Your wish list has been shared.')); $this->_redirect('*/*', array('wishlist_id' => $wishlist->getId())); } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError($e->getMessage()); $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); } }
/** * Update wishlist item comments * * @return ResponseInterface|void * @throws NotFoundException */ public function execute() { if (!$this->_formKeyValidator->validate($this->getRequest())) { return $this->_redirect('*/*/'); } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(); } $post = $this->getRequest()->getPost(); if ($post && isset($post['description']) && is_array($post['description'])) { $updatedItems = 0; foreach ($post['description'] as $itemId => $description) { $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item')->load($itemId); if ($item->getWishlistId() != $wishlist->getId()) { continue; } // Extract new values $description = (string) $description; if ($description == $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->defaultCommentString()) { $description = ''; } elseif (!strlen($description)) { $description = $item->getDescription(); } $qty = null; if (isset($post['qty'][$itemId])) { $qty = $this->quantityProcessor->process($post['qty'][$itemId]); } if (is_null($qty)) { $qty = $item->getQty(); if (!$qty) { $qty = 1; } } elseif (0 == $qty) { try { $item->delete(); } catch (\Exception $e) { $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); $this->messageManager->addError(__('Can\'t delete item from wishlist')); } } // Check that we need to save if ($item->getDescription() == $description && $item->getQty() == $qty) { continue; } try { $item->setDescription($description)->setQty($qty)->save(); $updatedItems++; } catch (\Exception $e) { $this->messageManager->addError(__('Can\'t save description %1', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($description))); } } // save wishlist model for setting date of last update if ($updatedItems) { try { $wishlist->save(); $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); } catch (\Exception $e) { $this->messageManager->addError(__('Can\'t update wish list')); } } if (isset($post['save_and_share'])) { $this->_redirect('*/*/share', array('wishlist_id' => $wishlist->getId())); return; } } $this->_redirect('*', array('wishlist_id' => $wishlist->getId())); }