public function saveAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { if (!Zend_Validate::is($data["email"], "emailAddress")) { throw new Exception($this->_("Please, enter a correct email address.")); } $user = new Backoffice_Model_User(); $dummy = new Backoffice_Model_User(); $dummy->find($data["email"], "email"); $isNew = true; if (!empty($data["id"])) { $user->find($data["id"]); $isNew = !$user->getId(); } $user->addData($data); if ($dummy->getEmail() == $user->getEmail() and $dummy->getId() != $user->getId()) { throw new Exception($this->_("We are sorry but this email address already exists.")); } if ($isNew and empty($data["password"])) { throw new Exception($this->_("Please, enter a password.")); } if (!empty($data["password"]) and $data["password"] != $data["confirm_password"]) { throw new Exception($this->_("Passwords don't match")); } if (!empty($data["password"])) { $user->setPassword($data["password"]); } $user->save(); $data = array("success" => 1, "message" => $this->_("User successfully saved")); } catch (Exception $e) { $data = array("error" => 1, "message" => $e->getMessage()); } $this->_sendHtml($data); } }