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; } }
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; } }
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; } }
function searchResourceModel($searchCriteriaForm) { $formObjRaw = new FormDTO(SEARCH_USER_FORM, $searchCriteriaForm); $responseDTO = new ResponseDTO(SEARCH_USER_FORM); try { $formDataObj = $formObjRaw->getFormData(); $validator = new FormValidator(SEARCH_USER_FORM, $formDataObj); $validationError = $validator->checkAll(); if (sizeof($validationError) == 0) { $userDAO = new UserDAO(); $userDTOList = $userDAO->getUserInfoByCriteria($formDataObj); return $userDTOList; } else { if (array_key_exists(NAME, $validationError)) { $responseDTO->setErrField(NAME, $validationError[NAME]); } return $responseDTO; } } catch (PDOException $pdoe) { throw $pdoe; } catch (UserNotAuthenticatedExceptionDTO $authExp) { throw $authExp; } catch (Exception $e) { throw $e; } }
public function commentAPostModel($commentForm, $postId = NULL) { $responseDTO = new ResponseDTO(WRITE_COMMENT_FORM); $formObjRaw = new FormDTO(WRITE_COMMENT_FORM, $commentForm); $formObjRaw->setSubElementId($postId); try { $formDataObj = $formObjRaw->getFormData(); $responseDTO->setSubElementId($formDataObj[WRITE_COMMENT_FORM . POSTID]); $validator = new FormValidator(WRITE_COMMENT_FORM, $formDataObj); $validationError = $validator->checkAll(); if (sizeof($validationError) == 0) { $timestamp = date(DATE_FORMAT); $userLogged = SessionUtils::getUserLogged(); $newCommentDTO = new CommentDTO(NULL, $formDataObj[WRITE_COMMENT_FORM . TEXT], $timestamp, $formDataObj[WRITE_COMMENT_FORM . POSTID], $userLogged); $postDAO = new PostDAO(); $commentDTO = $postDAO->insertNewComment($newCommentDTO); if ($commentDTO->getCommentid() == 0) { $responseDTO->setResponseSucc("Non è stato possibile inserire il commento del post"); } else { DataModelUtils::notifyAction($commentDTO->getCommentid() . SEPARATOR . $formDataObj[WRITE_COMMENT_FORM . POSTID] . SEPARATOR . $userLogged->getUserId() . SEPARATOR . SessionUtils::getDashboardId(), WRITE_COMMENT_FORM); return $commentDTO; } } else { if (array_key_exists(TEXT, $validationError)) { $responseDTO->setErrField(TEXT, $validationError[TEXT]); } return $responseDTO; } } catch (PDOException $pdoe) { throw $pdoe; } catch (UserNotAuthenticatedExceptionDTO $authExp) { throw $authExp; } catch (Exception $e) { throw $e; } }
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; } }
function deletePhotoModel($photoId, $filename) { $responseDTO = new ResponseDTO(DELETE_PHOTO_FORM); try { $userLogged = SessionUtils::getUserLogged(); $defaultUserPhotoProfileId = $userLogged->getProfilePhoto()->getPhotoId(); $photoDAO = new PhotoDAO(); if ($photoId == $defaultUserPhotoProfileId) { $uploadedPhoto = new PhotoDTO(1, DEFAULT_USER_PHOTOPROFILE_URL); $updateProfilePhoto = $photoDAO->updateProfilePhoto($uploadedPhoto); $userLogged = SessionUtils::getUserLogged(); $userLogged->setProfilePhoto($uploadedPhoto); SessionUtils::setUserLogged($userLogged); } $deletedPhoto = $photoDAO->deletePhotoInAlbum($photoId); $deletedPhoto = $photoDAO->deletePhoto($photoId); if ($deletedPhoto != 1) { $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'eliminazione della foto"); $responseDTO->setSubElementId($photoId); } else { FileUtils::deletePhotoOnServer($filename); $responseDTO->setResponseSucc("#photo" . $photoId); } return $responseDTO; } catch (PDOException $pdoe) { throw $pdoe; } catch (UserNotAuthenticatedExceptionDTO $authExp) { throw $authExp; } catch (Exception $e) { throw $e; } }
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; } }