made some token work

This commit is contained in:
neerholt 2021-03-09 13:54:20 +01:00
parent ac6b5a6bd9
commit ff749d80d4
2 changed files with 61 additions and 52 deletions

View File

@ -1,6 +1,8 @@
<?php
require_once "../../../bootstrap.php";
use Backend\Models\GameData;
use function Backend\Controllers\groupViaToken;
use Backend\Models\Group;
$isImages = false;
@ -8,69 +10,76 @@ session_start();
if(isset($_SESSION['token'])){
if(isset($_POST['submitUpload'])){
//Get the data from the user form
$gameFile = $_FILES['gameFile'];
$desc = $_POST['description'];
$title = $_POST['gameTitle'];
$thumbnail = $_FILES['thumbnailFile'];
$isWebBased = isset( $_POST['isWebBased']);
$group = groupViaToken($_SESSION['token']);
if(!isset($group->game_data_id)){
if(isset($_POST['submitUpload'])){
//Get the data from the user form
$gameFile = $_FILES['gameFile'];
$desc = $_POST['description'];
$title = $_POST['gameTitle'];
$thumbnail = $_FILES['thumbnailFile'];
$isWebBased = isset( $_POST['isWebBased']);
//Handle data for game files
$gameFileName = $_FILES['gameFile']['name'];//Game name
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
$gameFileError =$_FILES['gameFile']['error'];//File error
//Handle data for game files
$gameFileName = $_FILES['gameFile']['name'];//Game name
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
$gameFileError =$_FILES['gameFile']['error'];//File error
$fileExtGame = explode('.', $gameFileName);
$fileActualExtGame = strtolower(end($fileExtGame));
$fileExtGame = explode('.', $gameFileName);
$fileActualExtGame = strtolower(end($fileExtGame));
//Handle data for thumbnail files
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
//Handle data for thumbnail files
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
$fileExtThumb = explode('.', $thumbnailFileName);
$fileActualExtThumb = strtolower(end($fileExtThumb));
$fileExtThumb = explode('.', $thumbnailFileName);
$fileActualExtThumb = strtolower(end($fileExtThumb));
$allowedFileTypeGame = array('zip');
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
$allowedFileTypeGame = array('zip');
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
if(in_array($fileActualExtGame,$allowedFileTypeGame) || in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
if($gameFileError === 0 || $thumbnailFileError === 0){
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
if(in_array($fileActualExtGame,$allowedFileTypeGame) || in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
if($gameFileError === 0 || $thumbnailFileError === 0){
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
if(!empty($thumbnailFileName)){
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
$isImages = true;
}
if(!empty($thumbnailFileName)){
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
$isImages = true;
}
if(empty($gameFileName)){
header("location: ../../../Frontend/index.php?error=emptyFile");
exit();
}else{
$gameData = new GameData();
$gameData->game_name = $title;
$gameData->game_link = $gameFileNewName;
$gameData->description = $desc;
if($isImages) $gameData->img = $thumbnailFileNewName;
$gameData->is_web_Based = $isWebBased;
$gameData->save();
if(empty($gameFileName)){
header("location: ../../../Frontend/index.php?error=emptyFile");
exit();
}else{
$gameData = new GameData();
$gameData->game_name = $title;
$gameData->game_link = $gameFileNewName;
$gameData->description = $desc;
if($isImages) $gameData->img = $thumbnailFileNewName;
$gameData->is_web_Based = $isWebBased;
$gameData->save();
rename($gameFileTmp,"../../Games/".$gameFileNewName);
if($isImages){
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
$group->gameData()->associate($gameData);
$group->save();
rename($gameFileTmp,"../../Games/".$gameFileNewName);
if($isImages){
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
}
}
}else{
echo "Der var en fejl med at uploade din file";
}
}else{
echo "Wrong file type";
}
}else{
echo "Der var en fejl med at uploade din file";
}
}else{
echo "Wrong file type";
}
}
}

View File

@ -17,7 +17,7 @@ $gameJam = GameJam::firstOrCreate([
<title>HTML Tutorial</title>
<body>
<form action="Controllers/User/SigningUp.php" method="POST">
<form action="Controllers/Group/SigningUp.php" method="POST">
<input type="text" name="groupName" placeholder="Group name">
<input type="number" name="groupAmount" placeholder="Group Amount">
<input type="number" name="gameJamId" placeholder="Game Jam id">
@ -26,7 +26,7 @@ $gameJam = GameJam::firstOrCreate([
</form>
<form action="Controllers/User/Login.php" method="POST">
<form action="Controllers/Group/Login.php" method="POST">
<input type="text" name="groupName" placeholder="Group name">
<input type="password" name="password" placeholder="password">
<input type="submit" name="login" value="login">