Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
Minik Gaarde Lambrecht 2021-03-19 13:38:30 +01:00
commit b805390b6b
23 changed files with 158 additions and 112 deletions

View File

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

View File

@ -0,0 +1,22 @@
<?php
require_once "../../../bootstrap.php";
require_once "Admin.php";
use Backend\Models\AdminUser;
if (isAdmin()){
if (isset($_POST["newAdmin"])){
$admin = new AdminUser();
$admin->user_name = $_POST["newUsername"];
$admin->password = $_POST["newPassword"];
if ($admin->save()){
http_response_code(201);
}else{
http_response_code(500);
}
}else{
http_response_code(400);
}
}else{
http_response_code(401);
}

View File

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

View File

@ -14,6 +14,7 @@ if(isset($_GET['gameDataId'])){
$openGameDataStream = GameData::all(); $openGameDataStream = GameData::all();
} }
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'); header('Content-Type: application/json;charset=UTF-8');
echo $openGameDataStream->toJson(JSON_PRETTY_PRINT); echo $openGameDataStream->toJson(JSON_PRETTY_PRINT);

View File

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

View File

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

View File

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

View File

@ -16,3 +16,5 @@ if(isset($_GET['gameJamId'])){
header('Content-Type: application/json;charset=UTF-8'); header('Content-Type: application/json;charset=UTF-8');
echo $dbValue->toJson(JSON_PRETTY_PRINT); echo $dbValue->toJson(JSON_PRETTY_PRINT);
//var_dump(headers_list());

View File

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

View File

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

View File

@ -12,5 +12,7 @@ else{
$groups = Group::all(); $groups = Group::all();
} }
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'); header('Content-Type: application/json;charset=UTF-8');
echo $groups->toJson(JSON_PRETTY_PRINT); echo $groups->toJson(JSON_PRETTY_PRINT);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,9 +21,14 @@ if(isAdmin() && isset($_GET['gameJamId'])){
$winningGroups->push($group); $winningGroups->push($group);
} }
} }
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'); header('Content-Type: application/json;charset=UTF-8');
echo $winningGroups->toJson(JSON_PRETTY_PRINT); echo $winningGroups->toJson(JSON_PRETTY_PRINT);
}else{
http_response_code(401);
} }

View File

@ -8,15 +8,25 @@ use \Backend\Models\GameJam;
use \Illuminate\Support\Collection; use \Illuminate\Support\Collection;
if (!isAdmin()){ if (!isAdmin()){
if(isset($_POST['genKeyWord'])){ if(isset($_GET['genKeyWord'])){
$gameJamId = $_POST['gameJamId']; $gameJamId = $_GET['gameJamId'];
$game_jam = GameJam::find($gameJamId); $game_jam = GameJam::find($gameJamId);
$all_group_in_game_jam_id = Group::where("game_jam_id", $game_jam->id)->pluck("id")->toArray(); $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(); $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->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'); header('Content-Type: application/json;charset=UTF-8');
echo $find_all_keywords->pluck("key_word")->toJson(JSON_PRETTY_PRINT); 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 //Try to save it
if(!$keyword->save()){ if(!$keyword->save()){
header("location: ../../../Frontend/index.html?error=FailedToSave"); http_response_code(500);
exit();
}else{ }else{
header("location: ../../../Frontend/index.html?success=KeyWordSaved"); http_response_code(201);
exit();
} }
}else{ }else{
header("location: ../../../Frontend/index.html?error=YouCantSubmitAnyMoreKeyWords"); echo "limited upload reached";
exit(); http_response_code(400);
} }
}else{ }else{
header("location: ../../../Frontend/index.html?error=CouldNotSubmitKeyWord"); http_response_code(400);
exit();
} }
}else{ }else{
header("location: ../../../Frontend/index.html?error=NotLogin"); http_response_code(401);
exit();
} }

View File

@ -33,6 +33,21 @@ $gameJam = GameJam::firstOrCreate([
<input type="submit" name="login" value="login"> <input type="submit" name="login" value="login">
</form> </form>
<?php
//print_r(headers_list());
$h = apache_request_headers();
foreach ($h as $name => $value) {
echo "$name: $value <br>";
}
echo "<br>";
var_dump(headers_list());
?>
</body> </body>
</html> </html>

View File

@ -6,10 +6,14 @@ $(window).on("load", function(){
function dataFetch(){ function dataFetch(){
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/Game-Jaming/Backend/Controllers/FileHandler/GetGameData.php?gameJamId=1", url: "/Game-Jaming/Backend/controllers/GameJam/GetGameJam.php",
success: function(result){ success: function(result){
console.log(result); console.log(result[0].name);
console.log(result[0].game_link)
} }
}); });
} }
//console.log(result.name); ?gameJamId=1
//console.log(result[0].name); uden ?gameJamId=1