Added http response code

This commit is contained in:
neerholt 2021-03-19 13:25:27 +01:00
parent 409556ca2e
commit 171e0a3765
18 changed files with 103 additions and 112 deletions

View File

@ -19,20 +19,18 @@ if(isset($_POST['aLogin'])){
$_SESSION['userName'] = $userName;
$_SESSION['admin'] = true;
$_SESSION['success'] = "You are now logged in";
header('location: ../../../Frontend/index.html?login=success');
http_response_code(200);
}else{
session_destroy();
header('location: ../../../Frontend/index.html?login=failed?reason=password');
exit();
echo "Fail to verify password";
http_response_code(401);
}
}else{
session_destroy();
header('location: ../../../Frontend/index.html?login=failed?reason=username');
exit();
echo "No user";
http_response_code(401);
}
}else{
header("location: ../../../Frontend/index.html?error=NoLogin");
exit();
http_response_code(400);
}

View File

@ -10,17 +10,13 @@ if (isAdmin()){
$admin->user_name = $_POST["newUsername"];
$admin->password = $_POST["newPassword"];
if ($admin->save()){
header("location: ../../../Frontend/Html/AdminPage.html?success=adminUserWasCreated");
exit();
http_response_code(201);
}else{
header("location: ../../../Frontend/Html/AdminPage.html?error=errorWhileSaving");
exit();
http_response_code(500);
}
}else{
header("location: ../../../Frontend/Html/AdminPage.html?error=input:newAdmin.notSet");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=isNotAdministrator");
exit();
http_response_code(401);
}

View File

@ -15,13 +15,14 @@ function ZipFileHandler(string $gameFileName, string $gameFileTmp){
if(in_array($headerType,$headerTypeMatch)){
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
if(empty($gameFileName)){
header("location: ../../../Frontend/index.html?error=emptyFile");
http_response_code(400);
exit();
}
rename($gameFileTmp,"../../Games/".$gameFileNewName);
return $gameFileNewName;
}else{
header("location: location: ../../../Frontend/index.html?error=Wrong%20File%20Type");
echo "Wrong file type";
http_response_code(400);
exit();
}
return NULL;
@ -42,13 +43,14 @@ function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
if(in_array($headerType,$headerTypeMatch)){
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
if(empty($thumbnailFileName)){
header("location: ../../../Frontend/index.html?error=emptyFile");
http_response_code(400);
exit();
}
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
return $thumbnailFileNewName;
}else{
header("location: location: ../../../Frontend/index.html?error=Wrong%20File%20Type");
echo "Wrong file type";
http_response_code(400);
exit();
}
return NULL;

View File

@ -1 +0,0 @@
<?php

View File

@ -36,14 +36,15 @@ if(isLogin()){
$gameData->img = imagesFileHandler($thumbnailFileName,$thumbnailFileTmp);
}
$gameData->is_web_Based = $isWebBased;
$gameData->save();
header("location: ../../../Frontend/index.html?success=UpdatedFiles");
exit();
if(!$gameData->save()){
http_response_code(500);
}else{
header("location: ../../../Frontend/index.html?error=FailedUpload");
exit();
http_response_code(201);
}
}else{
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=NoLogin");
exit();
http_response_code(401);
}

View File

@ -52,23 +52,24 @@ if(isLogin()){
$gameData->is_web_Based = $isWebBased;
$gameData->save();
$group->gameData()->associate($gameData);
$group->save();
header("location: ../../../Frontend/index.html?success=UploadedFile");
exit();
if(! $group->save()){
http_response_code(500);
}else{
http_response_code(201);
}
}
}else{
header("location: ../../../Frontend/group.php?error=UploadFail");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/group.php?error=TooManyUploads");
exit();
echo "Can only upload one file";
http_response_code(400);
}
}else{
header("location: ../../../Frontend/group.php?error=GameJamHasNotBegun");
exit();
echo "Can only upload when the game jam has started";
http_response_code(400);
}
}else{
header("location: ../../../Main.php?error=NoLogin");
exit();
http_response_code(401);
}

View File

@ -17,18 +17,14 @@ if(isAdmin()){
$gameJam->description = $_POST["description"];
if($gameJam->save()){
header("location: ../../../Frontend/Html/AdminPage.html?success=UploadedFile");
exit();
http_response_code(201);
}
else{
header("location: ../../../Frontend/Html/AdminPage.html?error=FailToSaveGameJam");
exit();
http_response_code(500);
}
}else{
header("location: ../../../Frontend/Html/AdminPage.html?error=FailedToMakeGameJam");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=NotAdmin");
exit();
http_response_code(401);
}

View File

@ -22,16 +22,14 @@ if(isAdmin()){
$gameJam->description = $_POST['description'];
if ($gameJam->save()) {
header("location: ../../../Frontend/Html/AdminPage.html?success=UpdatedFile");
exit();
http_response_code(201);
}else{
http_response_code(500);
}
}
}else{
header("location: ../../../Frontend/Html/AdminPage.html?error=FailedToUpdatedGameJam");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=NotAdmin");
exit();
http_response_code(401);
}

View File

@ -25,26 +25,23 @@ if(isset($_POST['login'])){
$_SESSION['groupName'] = $groupName;
$_SESSION['token'] = $token;
$_SESSION['success'] = "You are now logged in";
header('location: ../../../Frontend/index.php?login=success');
exit();
//header('location: ../../../Frontend/index.php?login=success');
//exit();
http_response_code(200);
}
else{
session_destroy();
header('location: ../../../Frontend/index.php?login=failed&?reason=token');
exit();
http_response_code(500);
}
}else{
session_destroy();
header('location: ../../../Frontend/index.php?login=failed&?reason=password');
exit();
http_response_code(401);
}
}
else{
}else{
session_destroy();
header('location: ../../../Frontend/index.php?login=failed&?reason=group');
exit();
http_response_code(400);
}

View File

@ -12,19 +12,17 @@ if(isAdmin()){
$password->password = password_hash($_POST['newPassword'], PASSWORD_DEFAULT);
echo $password;
if(!$password->save()){
header("location: ../../../Frontend/Html/AdminPage.html?error=FailedSaveResetPassword");
exit();
http_response_code(500);
}else{
http_response_code(201);
}
}else{
header("location: ../../../Frontend/Html/AdminPage.html?success=SavedResetPassword");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/Html/AdminPage.html?error=FailedToResetPassword");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=NotAdmin");
exit();
http_response_code(401);
}

View File

@ -37,19 +37,18 @@ if(isset($_POST['regGroup'])){
$password->remember_token = $token;
if(!$password->save()){
return;
http_response_code(500);
}else{
http_response_code(201);
}
$_SESSION['groupName'] = $groupName;
$_SESSION['token'] = $token;
$_SESSION['success'] = "You are now logged in";
header("location: ../../../Frontend/index.html?success=GroupRegister");
exit();
}else{
header("location: ../../../Frontend/index.html?error=CouldNotValidatePassword");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=FailedRegister");
exit();
http_response_code(400);
}

View File

@ -10,17 +10,17 @@ if(isLogin()){
$group->group_name = $_POST['groupName'];
$group->group_amount = $_POST['groupAmount'];
$group->game_jam_id = $_POST['gameJamId'];
$group->save();
header("location: ../../../Frontend/index.html?success=YouHaveUpdated");
exit();
if(!$group->save()){
http_response_code(500);
}else{
http_response_code(201);
}
}
}else{
header("location: ../../../Frontend/index.html?error=CouldNotUpdate");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=NotLogin");
exit();
http_response_code(401);
}

View File

@ -8,16 +8,16 @@ if(isLogin()){
$password = Password::firstWhere("group_id", groupViaToken($_SESSION["token"])->id);
if(passwordValidate($pass = $_POST['password'])){
$password->password = password_hash($pass,PASSWORD_DEFAULT);
$password->save();
header("location: ../../../Frontend/index.html?success=PasswordUpdated");
exit();
if(!$password->save()){
http_response_code(500);
}else{
http_response_code(201);
}
}
}else{
header("location: ../../../Frontend/index.html?error=CouldNotUpdated");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=NotLogin");
exit();
http_response_code(401);
}

View File

@ -14,17 +14,15 @@ if(isset($_POST['1Vote'])){
$vote->points += 1;
if(!empty($_POST['comment'])){
$vote->comment = $_POST['comment'];
}else{
header("location: ../../../Frontend/index.html?error=EmptyField");
exit();
}
$vote->save();
header("location: ../../../Frontend/index.html?success=YouHaveVoted");
exit();
if(!$vote->save()){
http_response_code(500);
}else{
http_response_code(201);
}
}
}else{
header("location: ../../../Frontend/index.html?error=YouCantVoted");
exit();
http_response_code(400);
}

View File

@ -7,4 +7,6 @@ if(isLogin()){
header('Content-Type: application/json;charset=UTF-8');
echo Vote::where('group_id',groupViaToken($_SESSION['token'])->id)->get()->toJson(JSON_PRETTY_PRINT);
}else{
http_response_code(401);
}

View File

@ -28,5 +28,7 @@ if(isAdmin() && isset($_GET['gameJamId'])){
echo $winningGroups->toJson(JSON_PRETTY_PRINT);
}else{
http_response_code(401);
}

View File

@ -14,11 +14,19 @@ if (!isAdmin()){
$all_group_in_game_jam_id = Group::where("game_jam_id", $game_jam->id)->pluck("id")->toArray();
$find_all_keywords = KeyWord::whereIn("group_id", $all_group_in_game_jam_id)->inRandomOrder()->get();
$game_jam->key_word = $find_all_keywords->first()->key_word;
$game_jam->save();
if(!$game_jam->save()){
http_response_code(500);
}else{
http_response_code(201);
}
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
header('Content-Type: application/json;charset=UTF-8');
echo $find_all_keywords->pluck("key_word")->toJson(JSON_PRETTY_PRINT);
}else{
http_response_code(400);
}
}else{
http_response_code(401);
}

View File

@ -25,23 +25,19 @@ if (isLogin()) {
//Try to save it
if(!$keyword->save()){
header("location: ../../../Frontend/index.html?error=FailedToSave");
exit();
http_response_code(500);
}else{
header("location: ../../../Frontend/index.html?success=KeyWordSaved");
exit();
http_response_code(201);
}
}else{
header("location: ../../../Frontend/index.html?error=YouCantSubmitAnyMoreKeyWords");
exit();
echo "limited upload reached";
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=CouldNotSubmitKeyWord");
exit();
http_response_code(400);
}
}else{
header("location: ../../../Frontend/index.html?error=NotLogin");
exit();
http_response_code(401);
}