public static function RequiresLoggedInUser($redirectTo) { if (!UserFacade::IsUserLoggenIn()) { $error = new Error(Error::NotAuthenticated, "You have to log in to get access to that page."); Site::Redirect($redirectTo, $error); } }
/** * Redirects the page to the root of the website * @param logout, if set to true will also log out the user. */ public static function BackToHome($logout = false) { if ($logout != false) { Site::Redirect(Site::GetBaseURL(true) . 'Logout' . URLPAGEEXT); } else { Site::Redirect(Site::GetBaseURL() . 'Home' . URLPAGEEXT); } }
$recipe = null; $id = Site::GetArgumentSafely('id'); if (Value::SetAndNotNull($id)) { $recipe = Recipe::Load($id); if (Value::SetAndNotNull($recipe)) { $recipe->LoadSteps(); $edit = false; //Value::SetAndEqualTo($recipe->GetUsertrue, $GLOBALS, 'EDIT', true); if (Value::SetAndNotNull($_POST, 'CommentInput') && Site::CheckSecurityToken()) { $message = Site::GetPostValueSafely('CommentInput'); $commentid = Site::GetPostValueSafely('CommentSelect'); if (!is_numeric($commentid)) { $commentid = EMPTYSTRING; } Comment::Insert($message, $id, $commentid); Site::Redirect(EMPTYSTRING); } } else { Site::BackToHome(); } } else { Site::BackToHome(); } // Page Output include_once 'Pages/OnAllPages.php'; $recipebox = new RTK_Box('recipebox'); $recipedescription = new RTK_Box(null, 'recipedescription'); $recipedescription->AddChild(new RTK_Header($recipe->GetTitle())); //if (!$edit) { $recipedescription->AddChild(new RTK_Link('EditRecipe'.URLPAGEEXT, 'Edit')); } if ($recipe->GetPicture() != null) { $recipedescription->AddChild(new RTK_Image('/' . $recipe->GetPicture()->GetFileName()));
if ($error->code != Error::NoError) { Site::Redirect("/register.php", $error); } $error = UserFacade::RegisterUser($user, $password); if ($error->code != Error::NoError) { Site::Redirect("/register.php", $error); } $error = UserFacade::LogUserIn($user, $password); if ($error->code != Error::NoError) { Site::Redirect("/log-in.php", $error); } } else { $error = new Error(Error::InvalidParameter, "No parameter has been sent."); Site::Redirect("/register.php", $error); } Site::Redirect("/index.php"); //Checks whether parameters are correct function ValidateParameters($user, $password, $retypedPassword) { if (empty($user)) { return new Error(Error::InvalidParameter, "User name cannot be empty."); } if (UserFacade::IsUserRegistered($user)) { return new Error(Error::NotUniqueValue, "User with provided name is already registered."); } if (empty($password)) { return new Error(Error::InvalidParameter, "Password cannot be empty."); } if (strcmp($password, $retypedPassword)) { return new Error(Error::InvalidParameter, "Passwords don't match to each other."); }
$actionName = $_POST["submit"]; $userId = UserFacade::GetLoggedUserId(); $error = new Error(); if ($championId == 0) { $error = new Error(Error::InvalidParameter, "Invalid champion chosen."); Site::Redirect("/manage-champions.php", $error); } $error = PerformAction($actionName, $championId, $userId); if ($error->code != Error::NoError) { Site::Redirect("/manage-champions.php", $error); } } else { $error = new Error(Error::InvalidParameter, "No parameter has been sent."); Site::Redirect("/manage-champions.php", $error); } Site::Redirect("/manage-champions.php"); //Based by provided action name, adds or removes provided champion. //Returns error code function PerformAction($actionName, $championId, $userId) { $error = new Error(); if (strcmp($actionName, "Add") == 0) { $error = ChampionFacade::AddChampionToUser($championId, $userId); } else { if (strcmp($actionName, "Remove") == 0) { $error = ChampionFacade::RemoveChampionFromUser($championId, $userId); } else { $error = new Error(Error::InvalidParameter, "Invalid action: " . $actionName); } } return $error;
Site::Redirect("/add-new-champion.php", $error); } $fileName = GenerateFileNameWithPath($championName); $error = SaveFile($file, $fileName); if ($error->code != Error::NoError) { Site::Redirect("/add-new-champion.php", $error); } $error = ChampionFacade::AddChampion($championName, $fileName); if ($error->code != Error::NoError) { Site::Redirect("/add-new-champion.php", $error); } } else { $error = new Error(Error::InvalidParameter, "No parameter has been sent."); Site::Redirect("/add-new-champion.php", $error); } Site::Redirect("/add-new-champion.php"); //Checks whether all provided parameters are correct function ValidateParameters($championName, $file) { if (strlen($championName) == 0) { return new Error(Error::InvalidParameter, "Invalid champion name."); } if (ChampionFacade::DoesChampionExists($championName)) { return new Error(Error::NotUniqueValue, "Provided champion already exists."); } if (!isset($file) || $file === null) { return new Error(Error::InvalidFile, "File has not been uploaded."); } $error = ValidateFile($file); if ($error->code != Error::NoError) { return $error;
/** * Logs the user out. **/ public static function LogOut() { // Clear the session and regenerate the id, on logout // ...but make sure that the failed attempts carry over to the new session $attempts = Login::GetAttempts(); session_unset(); session_regenerate_id(); Login::SetAttempts($attempts); Site::Redirect('http://' . BASEURL . 'Home' . URLPAGEEXT); }
<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/include/scripts/include-all.php"; Site::Redirect("/process/log-out.php");