public function savepostAction() { if ($data = $this->getRequest()->getPost()) { $user = new Backoffice_Model_User(); $check_email_user = new Backoffice_Model_User(); try { if (!empty($data['user_id'])) { $user->find($data['user_id']); if (!$user->getId()) { throw new Exception($this->_('An error occurred while saving your account. Please try again later.')); } } if (empty($data['email'])) { throw new Exception($this->_('The email is required')); } $isNew = (bool) (!$user->getId()); $check_email_user->find($data['email'], 'email'); if ($check_email_user->getId() and $check_email_user->getId() != $user->getId()) { throw new Exception($this->_('This email address is already used')); } if (isset($data['password'])) { if ($data['password'] != $data['confirm_password']) { throw new Exception($this->_('Your password does not match the entered password.')); } if (!empty($data['old_password']) and !$user->isSamePassword($data['old_password'])) { throw new Exception($this->_("The old password does not match the entered password.")); } if (!empty($data['password'])) { $user->setPassword($data['password']); unset($data['password']); } } else { if ($isNew) { throw new Exception($this->_('The password is required')); } } $user->addData($data)->save(); $this->getSession()->addSuccess($this->_('The account has been successfully saved')); $this->_redirect('backoffice/account/list'); } catch (Exception $e) { $this->getSession()->addError($e->getMessage()); if ($user->getId()) { $this->_redirect('backoffice/account/edit', array('user_id' => $user->getId())); } else { $this->_redirect('backoffice/account/new'); } } } }