Ejemplo n.º 1
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;
     }
 }
Ejemplo 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;
     }
 }
Ejemplo n.º 3
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;
     }
 }
Ejemplo n.º 4
0
 public static function saveAddressModel($latitude, $longitude, $formType)
 {
     $responseDTO = new ResponseDTO($formType);
     try {
         if (!is_null($longitude) && !is_null($latitude)) {
             $addressDTO = new AddressDTO($latitude, $longitude);
             $addressDAO = new AddressDAO();
             $existingAddress = $addressDAO->checkIfAddressExist($addressDTO);
             if (!is_null($existingAddress)) {
                 return $existingAddress;
             } else {
                 $addressComponents = FileUtils::callGoogleReverseGeocodingService($addressDTO);
                 $addressDTO->setStreet(isset($addressComponents[STREET]) ? $addressComponents[STREET] : NULL);
                 $addressDTO->setNumber(isset($addressComponents[NUMBER]) ? $addressComponents[NUMBER] : NULL);
                 $addressDTO->setCap(isset($addressComponents[CAP]) ? $addressComponents[CAP] : NULL);
                 $addressDTO->setCity(isset($addressComponents[CITY]) ? $addressComponents[CITY] : NULL);
                 $addressDTO->setCountry(isset($addressComponents[COUNTRY]) ? $addressComponents[COUNTRY] : NULL);
                 $result = $addressDAO->insertNewAddress($addressDTO);
                 if ($result != 0) {
                     $responseDTO->setErrField(ADDRESS, "Errore durante l'inserimento di questo indirizzo   LONGITUDE: " . $addressDTO->getLongitude());
                 } else {
                     $result = $addressDAO->insertNewUserAddressVisited($addressDTO);
                     return $addressDTO;
                 }
             }
             return $responseDTO;
         } else {
             $addressDTO = new AddressDTO();
             return $addressDTO;
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
Ejemplo n.º 5
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;
     }
 }
Ejemplo n.º 6
0
 function addAlbumModel($albumForm)
 {
     $formObjRaw = new FormDTO(ADD_ALBUM_FORM, $albumForm);
     $responseDTO = new ResponseDTO(ADD_ALBUM_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(ADD_ALBUM_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         //            $validationError = array();
         if (sizeof($validationError) == 0) {
             $userLogged = SessionUtils::getUserLogged();
             $uploadedPhoto = FileUtils::uploadPhotoModel($formDataObj[ADD_ALBUM_FORM . COVER], NULL, ADD_ALBUM_FORM);
             if (get_class($uploadedPhoto) === PHOTODTO) {
                 $userDAO = new UserDAO();
                 $userDTO = $userDAO->getUserByUserId($userLogged->getUserId());
                 $albumDAO = new AlbumDAO();
                 $albumDTO = new AlbumDTO(null, date(DATE_FORMAT), $formDataObj[ADD_ALBUM_FORM . TITLE], $uploadedPhoto, $userDTO);
                 $albumDTO = $albumDAO->insertNewAlbum($albumDTO);
                 if ($albumDTO->getAlbumId() != 0) {
                     $photoAlbumPath = FileUtils::createAlbumDirOnServer($userDTO->getUserId(), $albumDTO->getAlbumId());
                     DataModelUtils::notifyAction($albumDTO->getCover()->getPhotoId() . SEPARATOR . $albumDTO->getCover()->getPhotoUrl() . SEPARATOR . $albumDTO->getAlbumId() . SEPARATOR . $albumDTO->getTitle(), ADD_ALBUM_FORM);
                     return $albumDTO;
                 } else {
                     $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento dell'album");
                 }
             } else {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento della foto profilo");
             }
         } else {
             if (array_key_exists(TITLE, $validationError)) {
                 $responseDTO->setErrField(TITLE, $validationError[TITLE]);
             }
             if (array_key_exists(PHOTO, $validationError)) {
                 $responseDTO->setErrField(COVER, $validationError[PHOTO]);
             }
             SessionUtils::setFormValue($formDataObj);
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
Ejemplo n.º 7
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;
     }
 }
Ejemplo n.º 8
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;
     }
 }
Ejemplo n.º 9
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;
     }
 }
Ejemplo n.º 10
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;
     }
 }
Ejemplo n.º 11
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;
     }
 }
Ejemplo n.º 12
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;
     }
 }
Ejemplo n.º 13
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;
     }
 }
Ejemplo n.º 14
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;
     }
 }
Ejemplo n.º 15
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;
     }
 }