Exemplo n.º 1
0
 function deleteAlbumModel($albumId)
 {
     $responseDTO = new ResponseDTO(DELETE_ALBUM_FORM);
     try {
         $userLogged = SessionUtils::getUserLogged();
         $defaultAlbumId = $userLogged->getDefaultAlbumId();
         if ($defaultAlbumId == $albumId) {
             $responseDTO->setErrField(ERROR_RESPONSE, "Non puoi eliminare il tuo album di default");
             return $responseDTO;
         }
         $albumDAO = new AlbumDAO();
         $deletePhotoInAlbum = $albumDAO->deletePhotoInAlbum($albumId);
         $deletedAlbum = $albumDAO->deleteAlbumById($albumId);
         if ($deletedAlbum != 1) {
             $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'eliminazione dell'album");
             $responseDTO->setSubElementId($albumId);
         } else {
             $userLogged = SessionUtils::getUserLogged();
             FileUtils::deleteAlbumDirOnServer($userLogged->getUserId(), $albumId);
             if (isset($_POST[JAVASCRIPT_ON]) && $_POST[JAVASCRIPT_ON] === "Y") {
                 $responseDTO->setResponseSucc("#album" . $albumId);
             } else {
                 $responseDTO->setResponseSucc("Album eliminato con successo!");
             }
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 2
0
 public function addAlbum()
 {
     try {
         $model = $this->getModel();
         $newAlbumAjax = NULL;
         if (isset($_POST[JAVASCRIPT_ON]) && $_POST[JAVASCRIPT_ON] === "Y") {
             $newAlbum = $model->addAlbumModel($newAlbumAjax);
             echo json_encode($newAlbum->jsonSerialize());
         } else {
             $newAlbum = $model->addAlbumModel($newAlbumAjax);
             if (get_class($newAlbum) === ALBUMDTO) {
                 $responseDTO = new ResponseDTO(ADD_ALBUM_FORM);
                 $responseDTO->setResponseSucc("Album aggiunto con successo");
                 SessionUtils::setError($responseDTO);
             } else {
                 SessionUtils::setError($newAlbum);
             }
             header("Location: " . URL . ALBUM_CONTROLLER);
             exit;
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         parent::userNotLogged($authExp);
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 3
0
 public function changeUserProfileInfo($userId = NULL)
 {
     try {
         $model = $this->getModel();
         $newProfileInfoAjax = NULL;
         if (isset($_POST["changeUserInfoForm"])) {
             $newProfileInfoAjax = json_decode($_POST["changeUserInfoForm"], true);
             $newProfileInfo = $model->changeUserProfileInfoModel($newProfileInfoAjax, $userId);
             echo json_encode($newProfileInfo->jsonSerialize());
         } else {
             $newProfileInfo = $model->changeUserProfileInfoModel($newProfileInfoAjax, $userId);
             if (get_class($newProfileInfo) !== PERSONDTO) {
                 SessionUtils::setError($newProfileInfo);
             } else {
                 $responseDTO = new ResponseDTO(CHANGE_SETTINGS_FORM);
                 $responseDTO->setResponseSucc("Info aggiornate con successo!");
                 SessionUtils::setError($responseDTO);
             }
             header("Location: " . URL . PROFILE_SETTINGS_CONTROLLER);
             exit;
         }
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         parent::userNotLogged($authExp);
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 4
0
 function deleteUserModel($userId)
 {
     try {
         $responseDTO = new ResponseDTO(DELETE_FRIEND_FORM);
         $userDAO = new UserDAO();
         $oldUser = $userDAO->deleteUser($userId);
         $responseDTO->setResponseSucc("#friend" . $userId);
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 5
0
 public function forgotPasswordModel($forgotPasswordForm)
 {
     $formObjRaw = new FormDTO(FORGOT_PWD_FORM, $forgotPasswordForm);
     $responseDTO = new ResponseDTO(FORGOT_PWD_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(FORGOT_PWD_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $userDAO = new UserDAO();
             $userDTO = $userDAO->getUserByEmail($formDataObj[FORGOT_PWD_FORM . EMAIL]);
             if (is_null($userDTO)) {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Nessun user presente con questa mail");
             } else {
                 $newPassword = PasswordUtils::createRandomicPassword();
                 $userDTO->setPassword($newPassword);
                 $resultMail = DataModelUtils::sendMail($userDTO, FORGOT_PWD_FORM);
                 $hashedPwd = PasswordUtils::getPassword($newPassword);
                 $userDTO->setPassword($hashedPwd);
                 $result = $userDAO->updateUserPassword($userDTO);
                 if ($result != 1) {
                     $responseDTO->setErrField(ERROR_RESPONSE, "Problema nel cambio della password");
                 } else {
                     $responseDTO->setResponseSucc("Verra mandata una mail con una nuova password all'indirizzo " . $userDTO->getEmail());
                 }
             }
         } else {
             if (array_key_exists(EMAIL, $validationError)) {
                 $responseDTO->setErrField(EMAIL, $validationError[EMAIL]);
             }
             SessionUtils::setFormValue($formDataObj);
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 6
0
 public function deleteUser($userId)
 {
     try {
         $model = $this->getModel();
         $deletedUser = $model->deleteUserModel($userId);
         FileUtils::deleteAlbumDirOnServer($userId, NULL);
         if (isset($_POST[JAVASCRIPT_ON]) && $_POST[JAVASCRIPT_ON] === "Y") {
             echo json_encode($deletedUser->jsonSerialize());
         } else {
             $responseDTO = new ResponseDTO(DELETE_USER_FORM);
             $responseDTO->setResponseSucc("Utente eliminato con successo");
             SessionUtils::setError($responseDTO);
             header("Location: " . URL . USERLIST_CONTROLLER);
             exit;
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         parent::userNotLogged($authExp);
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 7
0
 public function denyFriendshipModel($notificationId, $userForm)
 {
     $formObjRaw = new FormDTO(DENY_FRIENDSHIP_FORM, $userForm);
     $formObjRaw->setSubElementId($notificationId);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $friendDAO = new FriendsDAO();
         $friendId = $friendDAO->deleteFriend($formDataObj[DENY_FRIENDSHIP_FORM . FRIENDID]);
         $notificationDAO = new NotificationDAO();
         $notificationDAO->deleteNotificationByNotificationId($notificationId);
         $responseDTO = new ResponseDTO(DENY_REGISTRATION_FORM);
         $responseDTO->setResponseSucc($notificationId);
         return $notificationId;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 8
0
 public function searchUser()
 {
     $model = $this->getModel();
     $searchCriteriaFormAjax = NULL;
     $jsonUserDTOList = [];
     try {
         if (isset($_GET["searchForm"])) {
             $searchCriteriaFormAjax = json_decode($_GET["searchForm"], true);
             $foundedResources = $model->searchResourceModel($searchCriteriaFormAjax);
             for ($i = 0; $i < sizeof($foundedResources); $i++) {
                 $index = 'friends' . $i;
                 $jsonUserDTOList[$index] = $foundedResources[$index]->jsonSerialize();
             }
             echo json_encode($jsonUserDTOList);
         } else {
             $foundedResources = $model->searchResourceModel($searchCriteriaFormAjax);
             if (get_class($foundedResources) === RESPONSEDTO) {
                 SessionUtils::setError($foundedResources);
             } else {
                 if (!is_null($foundedResources)) {
                     $responseDTO = new ResponseDTO(SEARCH_USER_FORM);
                     $responseDTO->setResponseSucc($foundedResources);
                     SessionUtils::setError($responseDTO);
                 }
             }
             header("Location: " . URL . FRIENDS_CONTROLLER);
             exit;
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         parent::userNotLogged($authExp);
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 9
0
 function commentAPost($postId = NULL)
 {
     try {
         $model = $this->getModel();
         $newCommentPostAjax = NULL;
         if (isset($_POST["commentAPostForm"])) {
             $newCommentPostAjax = json_decode($_POST["commentAPostForm"], true);
             $newComment = $model->commentAPostModel($newCommentPostAjax, $postId);
             echo json_encode($newComment->jsonSerialize());
         } else {
             $newComment = $model->commentAPostModel($newCommentPostAjax, $postId);
             if (get_class($newComment) !== COMMENTDTO) {
                 SessionUtils::setError($newComment);
             } else {
                 $responseDTO = new ResponseDTO(WRITE_POST_FORM);
                 $responseDTO->setResponseSucc("Commento aggiunto con successo");
                 SessionUtils::setError($responseDTO);
             }
             header("Location: " . URL . PROFILE_CONTROLLER);
             exit;
             //
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         parent::userNotLogged($authExp);
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 10
0
 function deleteFriendModel($friendId)
 {
     try {
         $responseDTO = new ResponseDTO(DELETE_FRIEND_FORM);
         $friendsDAO = new FriendsDAO();
         $oldFriend = $friendsDAO->deleteFriend($friendId);
         $responseDTO->setResponseSucc("friend" . $friendId);
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 11
0
 public function deleteCommentModel($commentId)
 {
     $responseDTO = new ResponseDTO(DELETE_COMMENT_FORM);
     try {
         $postDAO = new PostDAO();
         $deletedComment = $postDAO->deleteComment($commentId);
         if ($deletedComment != 1) {
             $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'eliminazione del commento");
             $responseDTO->setSubElementId($commentId);
         } else {
             if (isset($_POST[JAVASCRIPT_ON]) && $_POST[JAVASCRIPT_ON] === "Y") {
                 $responseDTO->setResponseSucc("#comment" . $commentId);
             } else {
                 $responseDTO->setResponseSucc("Commento eliminato con successo!");
             }
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 12
0
 function updateProfilePhotoModel($photoId, $filename)
 {
     $responseDTO = new ResponseDTO(UPDATE_PROFILE_PHOTO_FORM);
     try {
         $photoDAO = new PhotoDAO();
         $photoDTO = new PhotoDTO($photoId, $filename);
         $updateProfilePhoto = $photoDAO->updateProfilePhoto($photoDTO);
         $userLogged = SessionUtils::getUserLogged();
         $userLogged->setProfilePhoto($photoDTO);
         SessionUtils::setUserLogged($userLogged);
         $responseDTO->setResponseSucc("Foto profilo aggiornata con successo!");
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 13
0
 public function addPhoto()
 {
     try {
         $model = $this->getModel();
         $newPhotoAjax = NULL;
         if (isset($_POST[JAVASCRIPT_ON]) && $_POST[JAVASCRIPT_ON] === "Y") {
             $newPhoto = $model->addPhotoModel($newPhotoAjax, SessionUtils::getAlbumId());
             echo json_encode($newPhoto->jsonSerialize());
         } else {
             $newPhoto = $model->addPhotoModel($newPhotoAjax, SessionUtils::getAlbumId());
             if (get_class($newPhoto) === PHOTODTO) {
                 $responseDTO = new ResponseDTO(ADD_PHOTO_FORM);
                 $responseDTO->setResponseSucc("Foto aggiunta con successo!");
                 SessionUtils::setError($responseDTO);
             } else {
                 SessionUtils::setError($newPhoto);
             }
             header("Location: " . URL . PHOTO_CONTROLLER);
             exit;
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         parent::userNotLogged($authExp);
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 14
0
 function changeUserPwdModel($pwdForm)
 {
     $formObjRaw = new FormDTO(CHANGE_PWD_FORM, $pwdForm);
     $responseDTO = new ResponseDTO(CHANGE_PWD_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(CHANGE_PWD_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $userLogged = SessionUtils::getUserLogged();
             $hashedPwd = PasswordUtils::getPassword($formDataObj[CHANGE_PWD_FORM . PASSWORD]);
             $userDTO = new UserDTO($userLogged->getUserId(), NULL, $hashedPwd, NULL, NULL, NULL, NULL, NULL);
             $userDAO = new UserDAO();
             $userLoggedDTO = $userDAO->checkPassword($userDTO);
             if (is_null($userLoggedDTO)) {
                 $responseDTO->setResponseSucc("Questa password non esiste");
                 return $responseDTO;
             }
             $hashedPwd = PasswordUtils::getPassword($formDataObj[CHANGE_PWD_FORM . NEW_PASSWORD]);
             $userDTO->setPassword($hashedPwd);
             $userPwdUpdated = $userDAO->updateUserPassword($userDTO);
             return $userDTO;
         } else {
             if (array_key_exists(PASSWORD, $validationError)) {
                 $responseDTO->setErrField(PASSWORD, $validationError[PASSWORD]);
             }
             if (array_key_exists(NEW_PASSWORD, $validationError)) {
                 $responseDTO->setErrField(NEW_PASSWORD, $validationError[NEW_PASSWORD]);
             }
             if (array_key_exists(CONFIRM_PASSWORD, $validationError)) {
                 $responseDTO->setErrField(CONFIRM_PASSWORD, $validationError[CONFIRM_PASSWORD]);
             }
             //                var_dump($validationError);
             //                var_dump($responseDTO);die;
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }