public function savepostAction() { if ($datas = $this->getRequest()->getPost()) { $admin = new Admin_Model_Admin(); $current_admin = $this->getSession()->getAdmin(); $check_email_admin = new Admin_Model_Admin(); $html = ''; try { if (!empty($datas['admin_id'])) { $admin->find($datas['admin_id']); if (!$admin->getId() or $current_admin->getParentId() and $admin->getId() != $current_admin->getId()) { throw new Exception($this->_('An error occurred while saving your account. Please try again later.')); } } if (empty($datas['email'])) { throw new Exception($this->_('The email is required')); } $isNew = (bool) (!$admin->getId()); $check_email_admin->find($datas['email'], 'email'); if ($check_email_admin->getId() and $check_email_admin->getId() != $admin->getId()) { throw new Exception($this->_('This email address is already used')); } if (isset($datas['password'])) { if ($datas['password'] != $datas['confirm_password']) { throw new Exception($this->_('Your password does not match the entered password.')); } if (!empty($datas['old_password']) and !$admin->isSamePassword($datas['old_password'])) { throw new Exception($this->_("The old password does not match the entered password.")); } if (!empty($datas['password'])) { $admin->setPassword($datas['password']); unset($datas['password']); } } else { if ($isNew) { throw new Exception($this->_('The password is required')); } } if ($isNew) { $datas['parent_id'] = $current_admin->getId(); } $admin->addData($datas)->save(); $html = array('success' => 1); if ($current_admin->getParentId()) { $html = array_merge($html, array('success_message' => $this->_('The account has been successfully saved'), 'message_timeout' => false, 'message_button' => false, 'message_loader' => 1)); } else { $this->getSession()->addSuccess($this->_('The account has been successfully saved')); } } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
public function savepostAction() { if ($datas = $this->getRequest()->getPost()) { $admin = new Admin_Model_Admin(); $check_email_admin = new Admin_Model_Admin(); try { if (!empty($datas['admin_id'])) { $admin->find($datas['admin_id']); if (!$admin->getId()) { throw new Exception($this->_('An error occurred while saving your account. Please try again later.')); } } if (empty($datas['email'])) { throw new Exception($this->_('The email is required')); } $isNew = (bool) (!$admin->getId()); $check_email_admin->find($datas['email'], 'email'); if ($check_email_admin->getId() and $check_email_admin->getId() != $admin->getId()) { throw new Exception($this->_('This email address is already used')); } if (isset($datas['password'])) { if ($datas['password'] != $datas['confirm_password']) { throw new Exception($this->_('Your password does not match the entered password.')); } if (!empty($datas['old_password']) and !$admin->isSamePassword($datas['old_password'])) { throw new Exception($this->_("The old password does not match the entered password.")); } if (!empty($datas['password'])) { $admin->setPassword($datas['password']); unset($datas['password']); } } else { if ($isNew) { throw new Exception($this->_('The password is required')); } } $admin->addData($datas)->save(); $this->getSession()->addSuccess($this->_('The account has been successfully saved')); $this->_redirect('admin/backoffice/list'); } catch (Exception $e) { $this->getSession()->addError($e->getMessage()); if ($admin->getId()) { $this->_redirect('admin/backoffice/edit', array('admin_id' => $admin->getId())); } else { $this->_redirect('admin/backoffice/new'); } } } }