made some token work
This commit is contained in:
parent
ac6b5a6bd9
commit
ff749d80d4
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
require_once "../../../bootstrap.php";
|
require_once "../../../bootstrap.php";
|
||||||
use Backend\Models\GameData;
|
use Backend\Models\GameData;
|
||||||
|
use function Backend\Controllers\groupViaToken;
|
||||||
|
use Backend\Models\Group;
|
||||||
|
|
||||||
$isImages = false;
|
$isImages = false;
|
||||||
|
|
||||||
|
@ -8,69 +10,76 @@ session_start();
|
||||||
|
|
||||||
if(isset($_SESSION['token'])){
|
if(isset($_SESSION['token'])){
|
||||||
|
|
||||||
if(isset($_POST['submitUpload'])){
|
$group = groupViaToken($_SESSION['token']);
|
||||||
//Get the data from the user form
|
|
||||||
$gameFile = $_FILES['gameFile'];
|
if(!isset($group->game_data_id)){
|
||||||
$desc = $_POST['description'];
|
if(isset($_POST['submitUpload'])){
|
||||||
$title = $_POST['gameTitle'];
|
//Get the data from the user form
|
||||||
$thumbnail = $_FILES['thumbnailFile'];
|
$gameFile = $_FILES['gameFile'];
|
||||||
$isWebBased = isset( $_POST['isWebBased']);
|
$desc = $_POST['description'];
|
||||||
|
$title = $_POST['gameTitle'];
|
||||||
|
$thumbnail = $_FILES['thumbnailFile'];
|
||||||
|
$isWebBased = isset( $_POST['isWebBased']);
|
||||||
|
|
||||||
|
|
||||||
//Handle data for game files
|
//Handle data for game files
|
||||||
$gameFileName = $_FILES['gameFile']['name'];//Game name
|
$gameFileName = $_FILES['gameFile']['name'];//Game name
|
||||||
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
|
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
|
||||||
$gameFileError =$_FILES['gameFile']['error'];//File error
|
$gameFileError =$_FILES['gameFile']['error'];//File error
|
||||||
|
|
||||||
$fileExtGame = explode('.', $gameFileName);
|
$fileExtGame = explode('.', $gameFileName);
|
||||||
$fileActualExtGame = strtolower(end($fileExtGame));
|
$fileActualExtGame = strtolower(end($fileExtGame));
|
||||||
|
|
||||||
//Handle data for thumbnail files
|
//Handle data for thumbnail files
|
||||||
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
|
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
|
||||||
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
|
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
|
||||||
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
|
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
|
||||||
|
|
||||||
$fileExtThumb = explode('.', $thumbnailFileName);
|
$fileExtThumb = explode('.', $thumbnailFileName);
|
||||||
$fileActualExtThumb = strtolower(end($fileExtThumb));
|
$fileActualExtThumb = strtolower(end($fileExtThumb));
|
||||||
|
|
||||||
|
|
||||||
$allowedFileTypeGame = array('zip');
|
$allowedFileTypeGame = array('zip');
|
||||||
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
|
$allowedFileTypeThumbnail = array('gif', 'jpeg', 'png', 'svg');
|
||||||
|
|
||||||
if(in_array($fileActualExtGame,$allowedFileTypeGame) || in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
|
if(in_array($fileActualExtGame,$allowedFileTypeGame) || in_array($thumbnailFileName,$allowedFileTypeThumbnail)){
|
||||||
if($gameFileError === 0 || $thumbnailFileError === 0){
|
if($gameFileError === 0 || $thumbnailFileError === 0){
|
||||||
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
|
||||||
|
|
||||||
if(!empty($thumbnailFileName)){
|
if(!empty($thumbnailFileName)){
|
||||||
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
|
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
|
||||||
$isImages = true;
|
$isImages = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($gameFileName)){
|
if(empty($gameFileName)){
|
||||||
header("location: ../../../Frontend/index.php?error=emptyFile");
|
header("location: ../../../Frontend/index.php?error=emptyFile");
|
||||||
exit();
|
exit();
|
||||||
}else{
|
}else{
|
||||||
$gameData = new GameData();
|
$gameData = new GameData();
|
||||||
$gameData->game_name = $title;
|
$gameData->game_name = $title;
|
||||||
$gameData->game_link = $gameFileNewName;
|
$gameData->game_link = $gameFileNewName;
|
||||||
$gameData->description = $desc;
|
$gameData->description = $desc;
|
||||||
if($isImages) $gameData->img = $thumbnailFileNewName;
|
if($isImages) $gameData->img = $thumbnailFileNewName;
|
||||||
$gameData->is_web_Based = $isWebBased;
|
$gameData->is_web_Based = $isWebBased;
|
||||||
$gameData->save();
|
$gameData->save();
|
||||||
|
|
||||||
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
$group->gameData()->associate($gameData);
|
||||||
if($isImages){
|
|
||||||
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
$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";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@ $gameJam = GameJam::firstOrCreate([
|
||||||
<title>HTML Tutorial</title>
|
<title>HTML Tutorial</title>
|
||||||
<body>
|
<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="text" name="groupName" placeholder="Group name">
|
||||||
<input type="number" name="groupAmount" placeholder="Group Amount">
|
<input type="number" name="groupAmount" placeholder="Group Amount">
|
||||||
<input type="number" name="gameJamId" placeholder="Game Jam id">
|
<input type="number" name="gameJamId" placeholder="Game Jam id">
|
||||||
|
@ -26,7 +26,7 @@ $gameJam = GameJam::firstOrCreate([
|
||||||
</form>
|
</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="text" name="groupName" placeholder="Group name">
|
||||||
<input type="password" name="password" placeholder="password">
|
<input type="password" name="password" placeholder="password">
|
||||||
<input type="submit" name="login" value="login">
|
<input type="submit" name="login" value="login">
|
||||||
|
|
Loading…
Reference in New Issue