Exemplo n.º 1
0
 public function init()
 {
     parent::init();
     if (!preg_match("/admin_api_account_autologin/", $this->getFullActionName("_"))) {
         $username = $this->getRequest()->getServer("PHP_AUTH_USER");
         $password = $this->getRequest()->getServer("PHP_AUTH_PW");
         $user = new Api_Model_User();
         $user->find($username, "username");
         if (!$user->getId() or !$user->authenticate($password)) {
             $this->_forward("notauthorized");
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 public function deleteAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($data["user_id"])) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $user = new Api_Model_User();
             $user->find($data["user_id"]);
             if (!$user->getId()) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $user->delete();
             $data = array("success" => 1, "message" => $this->_("User successfully deleted"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
Exemplo n.º 3
0
 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);
     }
 }