public function saveAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { $user = new Api_Model_User(); $dummy = new Api_Model_User(); $dummy->find($data["username"], "username"); $isNew = true; $data["confirm_password"] = !empty($data["confirm_password"]) ? $data["confirm_password"] : ""; if (!empty($data["id"])) { $user->find($data["id"]); $isNew = !$user->getId(); } if ($isNew and empty($data["password"])) { throw new Exception($this->_("Please, enter a password.")); } if (empty($data["password"]) and empty($data["confirm_password"])) { unset($data["password"]); unset($data["confirm_password"]); } if (!empty($data["password"]) and $data["password"] != $data["confirm_password"]) { throw new Exception($this->_("Passwords don't match")); } $user->addData($data); if ($dummy->getUsername() == $user->getUsername() and $dummy->getId() != $user->getId()) { throw new Exception($this->_("We are sorry but this username already exists.")); } 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); } }