new database

This commit is contained in:
RundelhausCode 2021-04-19 09:15:15 +02:00
parent 24663071e6
commit 22a431da07
43 changed files with 423 additions and 302 deletions

View File

@ -7,31 +7,31 @@ use Backend\Models\AdminUser;
//Start the php session
session_start();
if(isset($_POST['aLogin'])){
if (isset($_POST['aLogin'])) {
$userName = $_POST["userName"];
$password = $_POST["password"];
$user = AdminUser::firstWhere('user_name', $userName );
if($user){
$user = AdminUser::firstWhere('user_name', $userName);
if ($user) {
$hashedPassword = $user->password;
if(password_verify($password, $hashedPassword )){
if (password_verify($password, $hashedPassword)) {
$_SESSION['userName'] = $userName;
$_SESSION['admin'] = true;
$_SESSION['success'] = "You are now logged in";
http_response_code(200);
makeAdminLogin($userName);
}else{
} else {
session_destroy();
http_response_code(401);
echo json_encode(["message" => "wrong password"]);
}
}else{
} else {
session_destroy();
http_response_code(401);
echo json_encode(["message" => "admin don't exist"]);
}
}else{
} else {
http_response_code(400);
}

View File

@ -4,20 +4,20 @@ require_once "Admin.php";
use Backend\Models\AdminUser;
if (isAdmin()){
if (isset($_POST["newAdmin"])){
if (isAdmin()) {
if (isset($_POST["newAdmin"])) {
$admin = new AdminUser();
$admin->user_name = $_POST["newUsername"];
$admin->password = $_POST["newPassword"];
if ($admin->save()){
if ($admin->save()) {
http_response_code(201);
}else{
} else {
http_response_code(500);
}
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "is not admin"]);
}

View File

@ -13,15 +13,15 @@ function ZipFileHandler(string $gameFileName, string $gameFileTmp): string
$headerType = mime_content_type($gameFileTmp);
$headerTypeMatch = array('application/zip');
if(in_array($headerType,$headerTypeMatch)){
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
if(empty($gameFileName)){
if (in_array($headerType, $headerTypeMatch)) {
$gameFileNewName = uniqid("", true) . "." . $fileActualExtGame;
if (empty($gameFileName)) {
http_response_code(400);
exit();
}
rename($gameFileTmp,"../../Games/".$gameFileNewName);
rename($gameFileTmp, "../../Games/" . $gameFileNewName);
return $gameFileNewName;
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "Wrong file type gameFile"]);
exit();
@ -39,17 +39,17 @@ function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp):
$fileActualExtThumb = strtolower(end($fileExtThumb));
$headerType = mime_content_type($thumbnailFileTmp);
$headerTypeMatch = array('image/png', 'image/jpeg','image/gif', 'image/svg+xml',);
$headerTypeMatch = array('image/png', 'image/jpeg', 'image/gif', 'image/svg+xml',);
if(in_array($headerType,$headerTypeMatch)){
$thumbnailFileNewName = uniqid("", true). "." . $fileActualExtThumb;
if(empty($thumbnailFileName)){
if (in_array($headerType, $headerTypeMatch)) {
$thumbnailFileNewName = uniqid("", true) . "." . $fileActualExtThumb;
if (empty($thumbnailFileName)) {
http_response_code(400);
exit();
}
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
rename($thumbnailFileTmp, "../../../Frontend/images/" . $thumbnailFileNewName);
return $thumbnailFileNewName;
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "Wrong file type thumbnailFile"]);
exit();

View File

@ -1,16 +1,21 @@
<?php
require_once "../../../bootstrap.php";
use \Backend\Models\GameData;
use \Backend\Models\Group;
use Backend\Models\Registration;
if(isset($_GET['gameDataId'])){
$openGameDataStream = GameData::find($_GET['gameDataId']);
}elseif(isset($_GET['groupId'])){
$openGameDataStream = Group::find($_GET['groupId'])->GameData();
}elseif (isset($_GET['gameJamId'])){
$gameDataIds = Group::where("game_jam_id",$_GET['gameJamId'])->pluck("game_data_id")->toArray();
if (isset($_GET['gameDataId'])) {
$openGameDataStream = GameData::find($_GET['gameDataId']);
} elseif (isset($_GET['registrationId'])) {
$openGameDataStream = Registration::find($_GET['registrationId']);
} elseif (isset($_GET['groupId'])) {
$registrationIds = Registration::where("group_id", $_GET['groupId'])->pluck("game_data_id")->toArray();
$openGameDataStream = GameData::whereIn("id", $registrationIds)->get();
} elseif (isset($_GET['gameJamId'])) {
$gameDataIds = Group::where("game_jam_id", $_GET['gameJamId'])->pluck("game_data_id")->toArray();
$openGameDataStream = GameData::whereIn("id", $gameDataIds)->get();
}else{
} else {
$openGameDataStream = GameData::all();
}

View File

@ -2,15 +2,31 @@
require_once "../../../bootstrap.php";
require_once('../Group/Group.php');
require_once('FileHandler.php');
use Backend\Models\GameData;
if(isLogin()){
if(isset($_POST['submitUpdate'])){
use Backend\Models\GameData;
use Backend\Models\Registration;
if (isLogin()) {
if (isset($_POST['submitUpdate'])) {
//Get the game data
$gameData = GameData::find($_POST['gameDataId']);
if ($gameData === null) {
http_response_code(400);
echo json_encode(["message" => "game data not found"]);
exit();
}
//Get the group
$group = groupViaToken($_SESSION['token']);
if (!in_array($gameData->id, Registration::where("group_id", $group->id)->pluck("game_data_id")->toArray())) {
http_response_code(401);
exit();
}
$gameFile = $_FILES['gameFile'];
$desc = $_POST['description'];
$title = $_POST['gameTitle'];
$thumbnail = $_FILES['thumbnailFile'];
$isWebBased = isset( $_POST['isWebBased']);
$isWebBased = isset($_POST['isWebBased']);
$gameFileName = $_FILES['gameFile']['name'];//Game name
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
@ -18,34 +34,29 @@ if(isLogin()){
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
$thumbnailFileError = $_FILES['thumbnailFile']['error'];//File error
//Get the group
$group = groupViaToken($_SESSION['token']);
//Get the game data, from the group
$gameData = GameData::find($group->game_data_id);
$gameData->game_name = $title;
if(isset($gameData) && $gameFileError === 0){
unlink("../../Games/".$gameData->game_link);
$gameData->game_link = ZipFileHandler($gameFileName,$gameFileTmp);
if (isset($gameData) && $gameFileError === 0) {
unlink("../../Games/" . $gameData->game_link);
$gameData->game_link = ZipFileHandler($gameFileName, $gameFileTmp);
}
$gameData->description = $desc;
if(isset($thumbnail) && $thumbnailFileError === 0){
unlink("../../../Frontend/images/".$gameData->img);
$gameData->img = imagesFileHandler($thumbnailFileName,$thumbnailFileTmp);
if (isset($thumbnail) && $thumbnailFileError === 0) {
unlink("../../../Frontend/images/" . $gameData->img);
$gameData->img = imagesFileHandler($thumbnailFileName, $thumbnailFileTmp);
}
$gameData->is_web_Based = $isWebBased;
if(!$gameData->save()){
http_response_code(500);
}else{
http_response_code(201);
if (!$gameData->save()) {
http_response_code(500);
} else {
http_response_code(201);
}
}else{
http_response_code(400);
} else {
http_response_code(400);
}
}else{
http_response_code(401);
echo json_encode(["message" => "is not login"]);
} else {
http_response_code(401);
echo json_encode(["message" => "is not login"]);
}

View File

@ -2,8 +2,10 @@
require_once "../../../bootstrap.php";
require_once('../Group/Group.php');
require_once('FileHandler.php');
use Backend\Models\GameData;
use Backend\Models\GameJam;
use Backend\Models\Registration;
use Backend\Models\Group;
@ -12,26 +14,37 @@ date_default_timezone_set("Europe/Copenhagen");
$isImages = false;
if(isLogin()){
if (isLogin()) {
if (isset($_POST['submitUpload'])) {
$group = groupViaToken($_SESSION['token']);
$gameJam = GameJam::find($_POST['gameJamId']);
if ($gameJam === null) {
http_response_code(400);
echo json_encode(["message" => "gameJam not found"]);
exit();
}
$registration = Registration::where('game_jam_id', $gameJam->id)->where("group_id", $group->id)->frist();
if ($registration === null) {
http_response_code(401);
echo json_encode(["message" => "group not registered for that game jam"]);
exit();
}
$group = groupViaToken($_SESSION['token']);
$gameJam = GameJam::find($group->game_jam_id);
$gameJamStartTime = strtotime($gameJam->start_time);
$gameJamEndTime = strtotime($gameJam->end_time);
$date = date('Y/m/d H:i:s', time());
$gameJamStartTime = strtotime($gameJam->start_time);
$gameJamEndTime = strtotime($gameJam->end_time);
$date = date('Y/m/d H:i:s', time());
$currentTime = strtotime($date);
$currentTime = strtotime($date);
if($gameJamStartTime <= $currentTime && $gameJamEndTime >= $currentTime){
if(!isset($group->game_data_id)){
if(isset($_POST['submitUpload'])){
if ($gameJamStartTime <= $currentTime && $gameJamEndTime >= $currentTime) {
if (!isset($registration->game_data_id)) {
//Get the data from the user form
$gameFile = $_FILES['gameFile'];
$desc = $_POST['description'];
$title = $_POST['gameTitle'];
$thumbnail = $_FILES['thumbnailFile'];
$isWebBased = isset( $_POST['isWebBased']);
$isWebBased = isset($_POST['isWebBased']);
$gameFileName = $_FILES['gameFile']['name'];//Game name
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
@ -39,40 +52,40 @@ if(isLogin()){
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
$thumbnailFileError =$_FILES['thumbnailFile']['error'];//File error
$thumbnailFileError = $_FILES['thumbnailFile']['error'];//File error
if($gameFileError === 0){
if ($gameFileError === 0) {
$gameData = new GameData();
$gameData->game_name = $title;
$gameData->game_link = ZipFileHandler($gameFileName,$gameFileTmp);
$gameData->game_link = ZipFileHandler($gameFileName, $gameFileTmp);
$gameData->description = $desc;
if(isset($thumbnail) && $thumbnailFileError === 0){
$gameData->img = imagesFileHandler($thumbnailFileName,$thumbnailFileTmp);
if (isset($thumbnail) && $thumbnailFileError === 0) {
$gameData->img = imagesFileHandler($thumbnailFileName, $thumbnailFileTmp);
}
$gameData->is_web_Based = $isWebBased;
$gameData->save();
$group->gameData()->associate($gameData);
if(! $group->save()){
http_response_code(500);
}else{
http_response_code(201);
}
$registration->gameData()->associate($gameData);
if (!$registration->save()) {
http_response_code(500);
} else {
http_response_code(201);
}
}else{
http_response_code(500);
} else {
http_response_code(500);
}
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "file already uploaded "]);
}
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "Can only upload one file"]);
echo json_encode(["message" => "Can only upload when the game jam has started"]);
}
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "Can only upload when the game jam has started"]);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "is not login"]);
}

View File

@ -4,13 +4,14 @@ header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 1000");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
header("Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE");
require_once (realpath(dirname(__FILE__) ."/../../../bootstrap.php"));
require_once(realpath(dirname(__FILE__) . "/../../../bootstrap.php"));
use Backend\Models\GameJam;
if(isset($_GET['gameJamId'])){
$dbValue = GameJam::find($_GET['gameJamId']);
}else{
if (isset($_GET['gameJamId'])) {
$dbValue = GameJam::find($_GET['gameJamId']);
} else {
$dbValue = GameJam::all();
}

View File

@ -1,34 +1,34 @@
<?php
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";
use Backend\Models\GameJam;
//var_dump($_POST);
//session_start();
if(isAdmin()){
if(isset($_POST['newGameJam'])){
$gameJam = New GameJam();
if (isAdmin()) {
if (isset($_POST['newGameJam'])) {
$gameJam = new GameJam();
$gameJam->name = $_POST["gameJamName"];
$gameJam->start_time = $_POST["startDate"]."T".$_POST["startTime"];
$gameJam->end_time = $_POST["endDate"]."T".$_POST["endTime"];
$gameJam->start_time = $_POST["startDate"] . "T" . $_POST["startTime"];
$gameJam->end_time = $_POST["endDate"] . "T" . $_POST["endTime"];
if (!empty($_POST['keyWord'])) {
$gameJam->key_word = $_POST['keyWord'];
}
$gameJam->description = $_POST["description"];
if($gameJam->save()){
if ($gameJam->save()) {
http_response_code(201);
}
else{
} else {
http_response_code(500);
}
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "is not admin"]);
}

View File

@ -1,39 +1,40 @@
<?php
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";
use Backend\Models\GameJam;
if(isAdmin()){
if(isset($_POST['updateGameJam'])) {
if (isAdmin()) {
if (isset($_POST['updateGameJam'])) {
$gameJam = GameJam::find($_POST['gameJamId']);
if($gameJam){
if ($gameJam) {
$gameJam->name = $_POST['gameJamName'];
$gameJam->start_time = $_POST["startDate"]."T".$_POST["startTime"];
$gameJam->start_time = $_POST["startDate"] . "T" . $_POST["startTime"];
$gameJam->end_time = $_POST["endDate"]."T".$_POST["endTime"];
$gameJam->end_time = $_POST["endDate"] . "T" . $_POST["endTime"];
if (!empty($_POST['keyWord'])) {
$gameJam->key_word = $_POST['keyWord'];
}else{
} else {
$gameJam->key_word = null;
}
$gameJam->description = $_POST['description'];
if ($gameJam->save()) {
http_response_code(201);
}else{
} else {
http_response_code(500);
}
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "game jam not found"]);
}
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "is not admin"]);
}

View File

@ -1,14 +1,14 @@
<?php
require_once "../../../bootstrap.php";
use Backend\Models\Group;
if (isset($_GET["groupId"])){
if (isset($_GET["groupId"])) {
$groups = Group::find($_GET["groupId"]);
}
elseif(isset($_GET["gameJameId"])){
$groups = Group::where("game_jam_id",$_GET["gameJameId"])->get();
}
else{
} elseif (isset($_GET["gameJameId"])) {
$registrationIds = Registration::where("game_jam_id", $_GET["gameJameId"])->pluck("game_data_id")->toArray();
$groups = Group::whereIn("id", $registrationIds)->get();
} else {
$groups = Group::all();
}

View File

@ -1,8 +1,9 @@
<?php
require_once (realpath(dirname(__FILE__) ."/../../../bootstrap.php"));
require_once(realpath(dirname(__FILE__) . "/../../../bootstrap.php"));
use Backend\Models\Group;
use Backend\Models\Password;
session_start();
@ -14,7 +15,7 @@ session_start();
function groupViaToken(string $token): ?Group
{
if($password = Password::firstWhere('remember_token', $token)){
if ($password = Password::firstWhere('remember_token', $token)) {
return Group::find($password->group_id);
}
return null;
@ -34,15 +35,14 @@ function isLogin(): bool
*/
function passwordValidate(string $password1): bool
{
$uppercase = preg_match('@[A-Z]@', $password1);
$lowercase = preg_match('@[a-z]@', $password1);
$number = preg_match('@[0-9]@', $password1);
$specialChars = preg_match('@[^\w]@', $password1);
$uppercase = preg_match('@[A-Z]@', $password1);
$lowercase = preg_match('@[a-z]@', $password1);
$number = preg_match('@[0-9]@', $password1);
$specialChars = preg_match('@[^\w]@', $password1);
if(!$uppercase || !$lowercase || !$number || !$specialChars || (strlen($password1) >= 8 && strlen($password1) <= 255) ) {
return true;
}
else return false;
if (!$uppercase || !$lowercase || !$number || !$specialChars || (strlen($password1) >= 8 && strlen($password1) <= 255)) {
return true;
} else return false;
}
function makeLogin(string $groupName, int $groupId)

View File

@ -9,44 +9,43 @@ use Illuminate\Support\Str;
//Start the php session
if(isset($_POST['login'])){
if (isset($_POST['login'])) {
$groupName = $_POST["groupName"];
$password = $_POST["password"];
$group = Group::firstWhere('group_name', $groupName );
if($group){
$hashedPassword = $group->password->password;
if(password_verify($password, $hashedPassword )){
$token = Str::random(100);
$groupPassword = Password::firstWhere('group_id', $group->id);
$groupPassword->remember_token = $token;
if($groupPassword->save()){
$_SESSION['token'] = $token;
$_SESSION['success'] = "You are now logged in";
makeLogin($groupName,$group->id);
//header('location: ../../../Frontend/index.php?login=success');
//exit();
http_response_code(200);
}
else{
session_destroy();
http_response_code(500);
}
$group = Group::firstWhere('group_name', $groupName);
if ($group) {
$hashedPassword = $group->password->password;
if (password_verify($password, $hashedPassword)) {
$token = Str::random(100);
$groupPassword = Password::firstWhere('group_id', $group->id);
$groupPassword->remember_token = $token;
if ($groupPassword->save()) {
$_SESSION['token'] = $token;
$_SESSION['success'] = "You are now logged in";
makeLogin($groupName, $group->id);
//header('location: ../../../Frontend/index.php?login=success');
//exit();
http_response_code(200);
} else {
session_destroy();
http_response_code(500);
}
}else{
session_destroy();
http_response_code(401);
echo json_encode(["message" => "Wrong password"]);
}
} else {
session_destroy();
http_response_code(401);
echo json_encode(["message" => "Wrong password"]);
}
}else{
session_destroy();
http_response_code(401);
echo json_encode(["message" => "group was not found"]);
}
} else {
session_destroy();
http_response_code(401);
echo json_encode(["message" => "group was not found"]);
}
}else{
} else {
http_response_code(400);
}

View File

@ -5,26 +5,26 @@ require_once "../Admin/Admin.php";
use \Backend\Models\Password;
//session_start();
if(isAdmin()){
if(isset($_POST['restPassword'])){
$password = Password::firstWhere("group_id",$_POST['groupId']);
if($password){
$password->password = password_hash($_POST['newPassword'], PASSWORD_DEFAULT);
if (isAdmin()) {
if (isset($_POST['restPassword'])) {
$password = Password::firstWhere("group_id", $_POST['groupId']);
if ($password) {
$password->password = password_hash($_POST['newPassword'], PASSWORD_DEFAULT);
echo $password;
if(!$password->save()){
if (!$password->save()) {
http_response_code(500);
}else{
} else {
http_response_code(201);
}
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "group not found"]);
}
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "is not admin"]);
}

View File

@ -11,34 +11,31 @@ use Illuminate\Support\Str;
$groupName = "";
$errors = array();
if(isset($_POST['regGroup'])){
if (isset($_POST['regGroup'])) {
if(passwordValidate($pass = $_POST['password'])){
if (passwordValidate($pass = $_POST['password'])) {
$group = new Group();
$group->gameJam()->associate(GameJam::find($_POST['gameJamId']));
$group->group_name = $groupName = $_POST['groupName'];
$group->group_amount = $_POST['groupAmount'];
if(!$group->save()){
if (!$group->save()) {
http_response_code(500);
exit();
}
$password = New Password();
$password = new Password();
$password->group()->associate($group);
$password->password = password_hash($pass ,PASSWORD_DEFAULT);
$password->password = password_hash($pass, PASSWORD_DEFAULT);
$token = Str::random(100);
$password->remember_token = $token;
if(!$password->save()){
if (!$password->save()) {
$group->delete();
http_response_code(500);
exit();
}
@ -46,14 +43,14 @@ if(isset($_POST['regGroup'])){
$_SESSION['groupName'] = $groupName;
$_SESSION['token'] = $token;
$_SESSION['success'] = "You are now logged in";
makeLogin($groupName,$group->id);
makeLogin($groupName, $group->id);
http_response_code(201);
echo json_encode(["message" => "you are login"]);
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "password not valid"]);
}
}else{
} else {
http_response_code(400);
}

View File

@ -4,26 +4,23 @@ require_once "Group.php";
use Backend\Models\Group;
if(isLogin()){
if (isLogin()) {
if (isset($_POST['updateGroup'])) {
if($group = groupViaToken($_SESSION['token'])){
$group->group_name = $_POST['groupName'];
$group->group_amount = $_POST['groupAmount'];
$group->game_jam_id = $_POST['gameJamId'];
if(!$group->save()){
http_response_code(500);
}else{
http_response_code(201);
}
}
else{
if ($group = groupViaToken($_SESSION['token'])) {
$group->group_name = $_POST['groupName'];
if (!$group->save()) {
http_response_code(500);
} else {
http_response_code(201);
}
} else {
http_response_code(400);
echo json_encode(["message" => "group not found"]);
}
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "is not login"]);
}

View File

@ -1,28 +1,28 @@
<?php
require_once "../../../bootstrap.php";
require_once "Group.php";
use Backend\Models\Password;
if(isLogin()){
if(isset($_POST['updatePassword'])){
if (isLogin()) {
if (isset($_POST['updatePassword'])) {
$password = Password::firstWhere("group_id", groupViaToken($_SESSION["token"])->id);
if(passwordValidate($pass = $_POST['password'])){
$password->password = password_hash($pass,PASSWORD_DEFAULT);
if(!$password->save()){
if (passwordValidate($pass = $_POST['password'])) {
$password->password = password_hash($pass, PASSWORD_DEFAULT);
if (!$password->save()) {
http_response_code(500);
}else{
} else {
http_response_code(201);
}
}
else{
} else {
http_response_code(400);
echo json_encode(["message" => "password not valid"]);
}
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "is not login"]);
}

View File

@ -1,30 +1,31 @@
<?php
use Backend\Models\Group;
use Backend\Models\GameData;
use Backend\Models\Vote;
require_once "../../../bootstrap.php";
require_once "Vote.php";
if(isset($_POST['1Vote'])){
if(VoteCheck($_POST['groupId'])){
if (isset($_POST['1Vote'])) {
if (VoteCheck($_POST['gameDataId'])) {
$vote = new Vote();
$vote->group()->associate(Group::find($_POST['groupId']));
$vote->gameDate()->associate(GameData::find($_POST['gameDataId']));
$vote->points += 1;
if(!empty($_POST['comment'])){
if (!empty($_POST['comment'])) {
$vote->comment = $_POST['comment'];
}
if(!$vote->save()){
if (!$vote->save()) {
http_response_code(500);
}else{
} else {
http_response_code(201);
}
} else{
} else {
http_response_code(403);
echo json_encode(["message" => "you have already voted"]);
}
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "you have already voted"]);
}

View File

@ -2,17 +2,18 @@
use Backend\Models\Group;
use Backend\Models\Vote;
require_once "../../../bootstrap.php";
if(isset($_POST['321Vote'])){
if (isset($_POST['321Vote'])) {
require "Vote.php";
//give 1 point
$vote = new Vote();
$vote->group()->associate(Group::find($_POST['1pGroupId']));
$vote->points += 1;
if(!empty($_POST['1pComment'])){
if (!empty($_POST['1pComment'])) {
$vote->comment = $_POST['1pComment'];
}
$vote->save();
@ -20,7 +21,7 @@ if(isset($_POST['321Vote'])){
$vote = new Vote();
$vote->group()->associate(Group::find($_POST['2pGroupId']));
$vote->points += 2;
if(!empty($_POST['2pComment'])){
if (!empty($_POST['2pComment'])) {
$vote->comment = $_POST['2pComment'];
}
$vote->save();
@ -28,7 +29,7 @@ if(isset($_POST['321Vote'])){
$vote = new Vote();
$vote->group()->associate(Group::find($_POST['3pGroupId']));
$vote->points += 3;
if(!empty($_POST['3pComment'])){
if (!empty($_POST['3pComment'])) {
$vote->comment = $_POST['3pComment'];
}
$vote->save();
@ -36,5 +37,4 @@ if(isset($_POST['321Vote'])){
exit();
}

View File

@ -1,13 +1,15 @@
<?php
use Backend\Models\Vote;
require_once "../../../bootstrap.php";
require_once "../Group/Group.php";
if(isLogin()){
if (isLogin()) {
header('Content-Type: application/json;charset=UTF-8');
echo json_encode(array('data' => Vote::where('group_id',groupViaToken($_SESSION['token'])->id)->get()->jsonSerialize()));
echo json_encode(array('data' => Vote::where('group_id', groupViaToken($_SESSION['token'])->id)->get()->jsonSerialize()));
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "not login"]);
}

View File

@ -1,14 +1,15 @@
<?php
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";
use Backend\Models\Group;
use Backend\Models\Vote;
use \Illuminate\Support\Collection;
if(isAdmin()){
if(isset($_GET['gameJamId'])) {
if (isAdmin()) {
if (isset($_GET['gameJamId'])) {
$groups = Group::where('game_jam_id', $_GET['gameJamId'])->get();
if($groups) {
if ($groups) {
$winningGroups = new Collection();
$i = -1;
foreach ($groups as $group) {
@ -27,16 +28,15 @@ if(isAdmin()){
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
header('Content-Type: application/json;charset=UTF-8');
echo json_encode(array('data' => $winningGroups->jsonSerialize()));
}
else{
} else {
http_response_code(400);
echo json_encode(["message" => "game jam not found"]);
}
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "not admin"]);
}

View File

@ -1,5 +1,6 @@
<?php
require_once "../../../bootstrap.php";
use \Backend\Models\Group;
/**
@ -9,18 +10,18 @@ use \Backend\Models\Group;
function VoteCheck(string $voteId): bool
{
$votes = array();
if(isset($_COOKIE["VotingReg"])) {
if (isset($_COOKIE["VotingReg"])) {
$votes = unserialize($_COOKIE["VotingReg"]);
foreach ($votes as $vote){
foreach ($votes as $vote) {
if($voteId === $vote) {
if ($voteId === $vote) {
return false;
}
}
}
array_push($votes,$voteId);
array_push($votes, $voteId);
setcookie("VotingReg", serialize($votes), time() + 86400, "/");
return true;

View File

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

View File

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

View File

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

View File

@ -2,21 +2,20 @@
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";
use Backend\Models\Group;
use \Backend\Models\KeyWord;
use \Backend\Models\GameJam;
use \Illuminate\Support\Collection;
use Backend\Models\Registration;
if (!isAdmin()){
if(isset($_GET['genKeyWord'])){
if (!isAdmin()) {
if (isset($_GET['genKeyWord'])) {
$gameJamId = $_GET['gameJamId'];
$game_jam = GameJam::find($gameJamId);
$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()->take(6)->get();
$all_registration_in_game_jam_id = Registration::where("game_jam_id", $game_jam->id)->pluck("id")->toArray();
$find_all_keywords = KeyWord::whereIn("group_id", $all_registration_in_game_jam_id)->inRandomOrder()->take(6)->get();
$game_jam->key_word = $find_all_keywords->first()->key_word;
if(!$game_jam->save()){
if (!$game_jam->save()) {
http_response_code(500);
}else{
} else {
http_response_code(201);
}
@ -24,10 +23,10 @@ if (!isAdmin()){
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
header('Content-Type: application/json;charset=UTF-8');
echo json_encode(array('data' => $find_all_keywords->jsonSerialize()));
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "is not admin"]);
}

View File

@ -1,18 +1,33 @@
<?php
require_once "../../../bootstrap.php";
require_once "../Group/Group.php";
use Backend\Models\GameJam;
use Backend\Models\Registration;
use Backend\Models\Group;
use Backend\Models\KeyWord;
session_start();
if (isLogin()) {
if(isset($_POST['submitKeyWord'])){
//Find the group id
if (isset($_POST['submitKeyWord'])) {
//Find the group
$group = groupViaToken($_SESSION['token']);
if($gameJam = GameJam::find($_POST["gameJamId"]) === null){
http_response_code(400);
echo json_encode(["message" => "gameJam not found"]);
exit();
}
$registration = Registration::where('game_jam_id', $gameJam->id)->where("group_id", $group->id)->frist();
if ($registration === null) {
http_response_code(401);
echo json_encode(["message" => "group not registered for that game jam"]);
exit();
}
//if statement to find out if the group have use all their keyWords
if(KeyWord::where('group_id', $group->id)->count()<$group->group_amount){
if (KeyWord::where('registration_id', $registration->id)->count() < $registration->group_amount) {
//Make a new keyword[Only to be used if you need to make a new of something]
$keyword = new KeyWord();
@ -21,23 +36,23 @@ if (isLogin()) {
$keyword->key_word = $_POST['key_word'];
//Make foreign key from the groups table to the keyWords table
$keyword->group()->associate($group);
$keyword->registration()->associate($registration);
//Try to save it
if(!$keyword->save()){
if (!$keyword->save()) {
http_response_code(500);
}else{
} else {
http_response_code(201);
}
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "limited upload reached"]);
}
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "not login"]);
}

View File

@ -1,11 +1,12 @@
<?php
require_once realpath(dirname(__FILE__) ."/../../bootstrap.php");
require_once realpath(dirname(__FILE__) . "/../../bootstrap.php");
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Capsule::schema()->create("admin_users", function (Blueprint $table){
Capsule::schema()->create("admin_users", function (Blueprint $table) {
$table->id();
$table->string("user_name");
$table->string("password");

View File

@ -1,12 +1,13 @@
<?php
//require bootstrap aka our database connection
require_once realpath(dirname(__FILE__) ."/../../bootstrap.php");
require_once realpath(dirname(__FILE__) . "/../../bootstrap.php");
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
//Create game_data table with the rows as id, gameLink, isWebBased and timestamp
Capsule::schema()->create("game_data", function (Blueprint $table){
Capsule::schema()->create("game_data", function (Blueprint $table) {
$table->id();
$table->string('game_name');
$table->string("game_link");

View File

@ -1,12 +1,13 @@
<?php
//require bootstrap aka our database connection
require_once realpath(dirname(__FILE__) ."/../../bootstrap.php");
require_once realpath(dirname(__FILE__) . "/../../bootstrap.php");
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
//Create game_jams table with the rows as id, name, startTime, endTime, keyWord, description and timestamp
Capsule::schema()->create("game_jams", function (Blueprint $table){
Capsule::schema()->create("game_jams", function (Blueprint $table) {
$table->id();
$table->string("name");
$table->dateTime("start_time");

View File

@ -1,17 +1,15 @@
<?php
//require bootstrap aka our database connection
require_once realpath(dirname(__FILE__) ."/../../bootstrap.php");
require_once realpath(dirname(__FILE__) . "/../../bootstrap.php");
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
//Create groups table with the rows as id, groupName, groupAmount, fkGameJam, votes, fkPassword, fkGameData and timestamp
Capsule::schema()->create("groups", function (Blueprint $table){
Capsule::schema()->create("groups", function (Blueprint $table) {
$table->id();
$table->string("group_name");
$table->integer("group_amount");
$table->foreignId("game_jam_id")->constrained("game_jams");
$table->foreignId("game_data_id")->nullable()->constrained("game_data");
$table->timestamps();
});

View File

@ -1,15 +1,16 @@
<?php
//require bootstrap aka our database connection
require_once realpath(dirname(__FILE__) ."/../../bootstrap.php");
require_once realpath(dirname(__FILE__) . "/../../bootstrap.php");
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
//Create key_words table with the rows as id, keyWord, fkGroup and timestamp
Capsule::schema()->create("key_words", function (Blueprint $table){
Capsule::schema()->create("key_words", function (Blueprint $table) {
$table->id();
$table->string('key_word');
$table->foreignId("group_id")->constrained("groups");
$table->foreignId("registrations_id")->constrained("registrations");
$table->timestamps();
});

View File

@ -1,12 +1,13 @@
<?php
//require bootstrap aka our database connection
require_once realpath(dirname(__FILE__) ."/../../bootstrap.php");
require_once realpath(dirname(__FILE__) . "/../../bootstrap.php");
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
//Create password table with the rows as id, password, rememberToken and timestamps
Capsule::schema()->create("passwords", function (Blueprint $table){
Capsule::schema()->create("passwords", function (Blueprint $table) {
$table->id();
$table->foreignId("group_id")->constrained("groups");
$table->string('password');

View File

@ -0,0 +1,17 @@
<?php
//require bootstrap aka our database connection
require_once realpath(dirname(__FILE__) . "/../../bootstrap.php");
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Capsule::schema()->create("registrations", function (Blueprint $table) {
$table->id();
$table->foreignId("group_id")->constrained("groups");
$table->integer("group_amount");
$table->foreignId("game_jam_id")->constrained("game_jams");
$table->foreignId("game_data_id")->unique()->nullable()->constrained("game_data");
$table->timestamps();
});

View File

@ -1,14 +1,15 @@
<?php
require_once realpath(dirname(__FILE__) ."/../../bootstrap.php");
require_once realpath(dirname(__FILE__) . "/../../bootstrap.php");
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Capsule::schema()->create("votes", function (Blueprint $table){
Capsule::schema()->create("votes", function (Blueprint $table) {
$table->id();
$table->foreignId("group_id")->constrained("groups");
$table->tinyInteger("points");
$table->text("comment")->nullable();
$table->foreignId("game_data_id")->constrained("game_data");
$table->timestamps();
});

View File

@ -17,6 +17,7 @@ require "GameJam.php"; //GameJam has no foreign key
require "GameData.php"; //GameData has no foreign key
require "Group.php"; //Group has foreign keys to the GameJam, GameData and Password tables hence we create it as one of the last tables in the database
require "Password.php"; //Password has no foreign key
require "Registration.php";
require "KeyWord.php"; //Group has foreign keys to the Group
require "Vote.php";
require "AdminUser.php";

View File

@ -1,7 +1,9 @@
<?php
namespace Backend\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class AdminUser extends Eloquent
{
protected $fillable = [
@ -9,5 +11,4 @@ class AdminUser extends Eloquent
];
}

View File

@ -1,14 +1,22 @@
<?php
namespace Backend\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class GameData extends Eloquent
{
protected $fillable = [
'game_name', 'game_link', 'is_web_Based', 'description' , "img"
'game_name', 'game_link', 'is_web_Based', 'description', "img"
];
public function group(){
return $this->hasOne(Group::class);
public function registration()
{
return $this->hasOne(Registration::class);
}
public function votes()
{
return $this->hasMany(Vote::class);
}
}

View File

@ -1,10 +1,13 @@
<?php
namespace Backend\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class GameJam extends Eloquent{
protected $fillable =[
class GameJam extends Eloquent
{
protected $fillable = [
'name',
'start_time',
'end_time',
@ -13,11 +16,10 @@ class GameJam extends Eloquent{
];
public function group(){
return $this->hasMany(Group::class);
}
public function hasVoted(){
return $this->hasMany(hasVoted::class);
public function registrations()
{
return $this->hasMany(Registration::class);
}
}

View File

@ -1,26 +1,24 @@
<?php
namespace Backend\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Group extends Eloquent
{
protected $fillable = [
'group_name', 'group_amount', 'votes'
];
public function gameJam(){
return $this->belongsTo(GameJam::class);
}
public function keyWord(){
return $this->hasMany(KeyWord::class);
}
public function gameData(){
return $this->belongsTo(GameData::class);
}
public function password(){
public function password()
{
return $this->hasOne(Password::class);
}
public function vote(){
return $this->hasMany(Vote::class);
public function registrations()
{
return $this->hasMany(Registration::class);
}
}

View File

@ -1,14 +1,19 @@
<?php
namespace Backend\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class KeyWord extends Eloquent{
protected $fillable =[
class KeyWord extends Eloquent
{
protected $fillable = [
'key_word'
];
public function group(){
return $this->belongsTo(Group::class);
public function registration()
{
return $this->belongsTo(Registration::class);
}
}

View File

@ -1,13 +1,18 @@
<?php
namespace Backend\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Password extends Eloquent{
protected $fillable =[
class Password extends Eloquent
{
protected $fillable = [
'password', 'remember_token'
];
public function group(){
public function group()
{
return $this->belongsTo(Group::class);
}

View File

@ -0,0 +1,35 @@
<?php
namespace Backend\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Registration extends Eloquent
{
protected $fillable = [
'group_amount'
];
public function group()
{
return $this->belongsTo(Group::class);
}
public function gameJam()
{
return $this->belongsTo(GameJam::class);
}
public function keyWords()
{
return $this->hasMany(KeyWord::class);
}
public function gameData()
{
return $this->belongsTo(GameData::class);
}
}

View File

@ -11,9 +11,9 @@ class Vote extends Eloquent
];
public function group()
public function gameDate()
{
return $this->belongsTo(Group::class);
return $this->belongsTo(GameData::class);
}
}