Esempio n. 1
0
 protected function validateOne()
 {
     setContentType("json");
     $pack = new Pack();
     $given = array_keys($_POST);
     $response["error"] = null;
     if (count($given) == 1) {
         if ($given[0] == "name") {
             $p = PackQuery::create()->filterByOwner($this->data["loggedUser"])->filterByName($_POST["name"])->findOne();
             if ($p) {
                 $response["error"] = array("name" => "name", "message" => "You can not have two packs with the same name.");
                 $this->viewString(json_encode($response));
                 return;
             }
             $pack->setName($_POST["name"]);
         } else {
             if ($given[0] == "description") {
                 $pack->setDescription($_POST["description"]);
             } else {
                 setHTTPStatusCode("400");
                 return;
             }
         }
         if (!$pack->validate()) {
             foreach ($pack->getValidationFailures() as $failure) {
                 if ($given[0] == $failure->getPropertyPath()) {
                     $response["error"] = array("name" => $failure->getPropertyPath(), "message" => $failure->getMessage());
                 }
             }
         }
         $this->viewString(json_encode($response));
     } else {
         setHTTPStatusCode("400");
     }
 }
Esempio n. 2
0
 protected function error406()
 {
     setHTTPStatusCode("406");
     $this->data["title"] = "Error406";
     $this->viewFile($this->template);
 }
Esempio n. 3
0
 public function changeAvatar()
 {
     if (isset($_POST["newAvatar"]) && $this->isLogged()) {
         $data = explode(',', $_POST["newAvatar"]);
         if (count($data) == 2 && $data[0] == "data:image/png;base64" && base64_decode($data[1])) {
             $dir = "includes/images/200x200/";
             $img = imagecreatefromstring(base64_decode($data[1]));
             do {
                 $name = token(20) . ".png";
                 $path = $dir . $name;
             } while (file_exists($path));
             $_SESSION["user"]->getImage()->setPath($name)->setThumbnailPath($name)->setType("200x200")->setDescription("Profilový obrázek uživatele " . $_SESSION["user"]->getUsername())->save();
             imagepng($img, $path);
             $dir = "includes/images/50x50/";
             $path = $dir . $name;
             imagepng(resizeImg($img, 50, 50), $path);
             $this->addPopup('success', 'Váš avatar byl úspěšně změněn.');
             redirectTo('/nastaveni');
         } else {
             setHTTPStatusCode("400");
         }
     } else {
         setHTTPStatusCode("400");
     }
 }
Esempio n. 4
0
 protected function validateOne()
 {
     setContentType("json");
     $user = new User();
     $given = array_keys($_POST);
     $response["error"] = null;
     if (count($given) == 1) {
         if ($given[0] == "username") {
             $user->setUsername($_POST["username"]);
         } else {
             if ($given[0] == "password") {
                 $user->setPassword($_POST["password"]);
             } else {
                 if ($given[0] == "email") {
                     $user->setEmail($_POST["email"]);
                 } else {
                     if ($given[0] == "name") {
                         $user->setName($_POST["name"]);
                     } else {
                         if ($given[0] == "surname") {
                             $user->setSurname($_POST["surname"]);
                         } else {
                             setHTTPStatusCode("400");
                             return;
                         }
                     }
                 }
             }
         }
         if (!$user->validate()) {
             foreach ($user->getValidationFailures() as $failure) {
                 if ($given[0] == $failure->getPropertyPath()) {
                     $response["error"] = array("name" => $failure->getPropertyPath(), "message" => $failure->getMessage());
                 }
             }
         }
         $this->viewString(json_encode($response));
     } else {
         setHTTPStatusCode("400");
     }
 }