public static function run() { if (!($user = CookieController::readSessionCookie())) { header("Location: home"); } elseif ($_SERVER["REQUEST_METHOD"] == "POST") { if (UserDatabase::updateUser($user, $_POST)) { # First Name if (isset($_POST["firstName"])) { $firstName = $_POST["firstName"]; if (strcmp($firstName, $user->getFirstName()) !== 0) { $user->setFirstName($firstName); } } # Last Name if (isset($_POST["lastName"])) { $lastName = $_POST["lastName"]; if (strcmp($lastName, $user->getLastName()) !== 0) { $user->setLastName($lastName); } } # Email if (isset($_POST["email"])) { $email = $_POST["email"]; if (strcmp($email, $user->getEmail()) !== 0) { $user->setEmail($email); } } # Handle if (isset($_POST["handle"])) { $handle = $_POST["handle"]; if (strcmp($handle, $user->getHandle()) !== 0) { $user->setHandle($handle); } } # About if (isset($_POST["about"])) { $about = $_POST["about"]; if (strcmp($about, $user->getAbout()) !== 0) { $user->setAbout($about); } } # Password if (isset($_POST["cur-password"]) && isset($_POST["new-password"]) && isset($_POST["confirm-password"])) { $curPassword = $POST["cur-password"]; echo $curPassword; $newPassword = $POST["new-password"]; $confirmPassword = $POST["confirm-password"]; if (strcmp($curPassword, $newPassword) !== 0) { $user->setPassword($curPassword, $newPassword, $confirmPassword); } } CookieController::setSessionCookie($user); header("Location: view-profile"); } else { EditProfileView::show($user); } } else { EditProfileView::show($user); } }
public static function refreshSessionCookie() { if (CookieController::cookieExists("session")) { $user = CookieController::readSessionCookie(); CookieController::setSessionCookie($user); return $user; } return false; }
public static function run() { if (CookieController::cookieExists("session")) { if (($user = CookieController::readSessionCookie()) === false) { header("Location: home"); } else { $maps = MapDatabase::getAllUserMaps($user->getID()); MyTripsView::show($maps); } } else { header("Location: home"); } }
public static function run($map) { if (CookieController::cookieExists("session")) { if (($user = CookieController::readSessionCookie()) !== false) { $map; if ($_SERVER["REQUEST_METHOD"] == "POST") { $mapID = ""; $mapName = ""; $latLng = ""; if (isset($_POST["map-id"])) { $mapID = $_POST["map-id"]; } if (isset($_POST["map-name"])) { $mapName = $_POST["map-name"]; } if (isset($_POST["lat-lng"])) { $latLng = $_POST["lat-lng"]; } $map = new Map($mapID, $mapName, $latLng); if (empty($mapID)) { MapDatabase::addMap($map, $user->getID()); } else { MapDatabase::updateMap($map); } MapView::show($map); } else { if (isset($_GET["selection"])) { $mapID = $_GET["selection"]; $map = MapDatabase::getMap($mapID); } MapView::show($map); } } else { header("Location: home"); } } else { header("Location: home"); } }
<body> <?php include "../includer.php"; $params = array("firstName" => "John", "lastName" => "Cena", "email" => "*****@*****.**", "handle" => "johnCena", "about" => "Wrestling Champion"); $user = new User($params); $user->resetErrors(); echo "<h1>setSessionCookie():<hr/>"; if (!CookieController::setSessionCookie($user)) { echo "<h3>Failure: returned false</h3>"; } elseif (is_null($_COOKIE) || !isset($_COOKIE["session"])) { echo "<h3>Failure: \$_COOKIE is null or session is not set</h3>"; } else { echo "<h3>Success</h3>"; } echo "<h1>readSessionCookie():<hr/>"; if (!($user = CookieController::readSessionCookie($user))) { echo "<h3>Failure</h3>"; } elseif (empty($user->getFirstName())) { echo "<h3>Failure</h3>"; } else { echo "<h3>Success</h3>"; } echo "<h1>refreshSessionCookie():<hr/>"; if (!($user = CookieController::refreshSessionCookie($user))) { echo "<h3>Failure</h3>"; } elseif (empty($user->getFirstName())) { echo "<h3>Failure</h3>"; } else { echo "<h3>Success</h3>"; } ?>