is->_initLayoutMessages('customer/session'); $this->_initLayoutMessages('catalog/session'); $block = $this->getLayout()->getBlock('customer_edit'); if ($block) { $block->setRefererUrl($this->_getRefererUrl()); } $data = $this->_getSession()->getCustomerFormData(true); $customer = $this->_getSession()->getCustomer(); if (!empty($data)) { $customer->addData($data); } if ($this->getRequest()->getParam('changepass') == 1) { $customer->setChangePassword(1); } $this->getLayout()->getBlock('head')->setTitle($this->__('Account Information')); $this->getLayout()->getBlock('messages')->setEscapeMessageFlag(true); $this->renderLayout(); } /** * Change customer password action */ public function editPostAction() { if (!$this->_validateFormKey()) { return $this->_redirect('*/*/edit'); } if ($this->getRequest()->isPost()) { /** @var $customer Mage_Customer_Model_Customer */ $customer = $this->_getSession()->getCustomer(); /** @var $customerForm Mage_Customer_Model_Form */ $customerForm = $this->_getModel('customer/form'); $customerForm->setFormCode('customer_account_edit') ->setEntity($customer); $customerData = $customerForm->extractData($this->getRequest()); $errors = array(); $customerErrors = $customerForm->validateData($customerData); if ($customerErrors !== true) { $errors = array_merge($customerErrors, $errors); } else { $customerForm->compactData($customerData); $errors = array(); // If password change was requested then add it to common validation scheme if ($this->getRequest()->getParam('change_password')) { $currPass = $this->getRequest()->getPost('current_password'); $newPass = $this->getRequest()->getPost('password'); $confPass = $this->getRequest()->getPost('confirmation'); $oldPass = $this->_getSession()->getCustomer()->getPasswordHash(); if ( $this->_getHelper('core/string')->strpos($oldPass, ':')) { list($_salt, $salt) = explode(':', $oldPass); } else { $salt = false; } if ($customer->hashPassword($currPass, $salt) == $oldPass) { if (strlen($newPass)) { /** * Set entered password and its confirmation - they * will be validated later to match each other and be of right length */ $customer->setPassword($newPass); $customer->setPasswordConfirmation($confPass); } else { $errors[] = $this->__('New password field cannot be empty.'); } } else { $errors[] = $this->__('Invalid current password'); } } // Validate account and compose list of errors if any $customerErrors = $customer->validate(); if (is_array($customerErrors)) { $errors = array_merge($errors, $customerErrors); } } if (!empty($errors)) { $this->_getSession()->setCustomerFormData($this->getRequest()->getPost()); foreach ($errors as $message) { $this->_getSession()->addError($message); } $this->_redirect('*/*/edit'); return $this; } try { $customer->cleanPasswordsValidationData(); $customer->save(); $this->_getSession()->setCustomer($customer) ->addSuccess($this->__('The account information has been saved.')); $this->_redirect('customer/account'); return; } catch (Mage_Core_Exception $e) { $this->_getSession()->setCustomerFormData($this->getRequest()->getPost()) ->addError($e->getMessage()); } catch (Exception $e) { $this->_getSession()->setCustomerFormData($this->getRequest()->getPost()) ->addException($e, $this->__('Cannot save the customer.')); } } $this->_redirect('*/*/edit'); } /** * Filtering posted data. Converting localized data if needed * * @param array * @return array */ protected function _filterPostData($data) { $data = $this->_filterDates($data, array('dob')); return $data; } /** * Check whether VAT ID validation is enabled * * @param Mage_Core_Model_Store|string|int $store * @return bool */ protected function _isVatValidationEnabled($store = null) { return $this->_getHelper('customer/address')->isVatValidationEnabled($store); } }