Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
@@ -8,3 +8,15 @@ function isAdmin(): bool
|
||||
return isset($_SESSION['admin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $userName
|
||||
*/
|
||||
function makeAdminLogin(string $userName)
|
||||
{
|
||||
setcookie("userName", $userName, [
|
||||
'expires' => 0,
|
||||
'samesite' => 'Strict',
|
||||
'path' => '/'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,17 @@ if(isset($_POST['aLogin'])){
|
||||
$_SESSION['admin'] = true;
|
||||
$_SESSION['success'] = "You are now logged in";
|
||||
http_response_code(200);
|
||||
makeAdminLogin($userName);
|
||||
}else{
|
||||
session_destroy();
|
||||
echo "Fail to verify password";
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "wrong password"]);
|
||||
}
|
||||
|
||||
}else{
|
||||
session_destroy();
|
||||
echo "No user";
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "admin don't exist"]);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
|
||||
@@ -19,4 +19,5 @@ if (isAdmin()){
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not admin"]);
|
||||
}
|
||||
@@ -5,7 +5,8 @@
|
||||
* @return string
|
||||
*/
|
||||
|
||||
function ZipFileHandler(string $gameFileName, string $gameFileTmp){
|
||||
function ZipFileHandler(string $gameFileName, string $gameFileTmp): string
|
||||
{
|
||||
$fileExtGame = explode('.', $gameFileName);
|
||||
$fileActualExtGame = strtolower(end($fileExtGame));
|
||||
|
||||
@@ -21,11 +22,10 @@ function ZipFileHandler(string $gameFileName, string $gameFileTmp){
|
||||
rename($gameFileTmp,"../../Games/".$gameFileNewName);
|
||||
return $gameFileNewName;
|
||||
}else{
|
||||
echo "Wrong file type";
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "Wrong file type gameFile"]);
|
||||
exit();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,8 @@ return NULL;
|
||||
* @param string $thumbnailFileTmp
|
||||
* @return string
|
||||
*/
|
||||
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
|
||||
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp): string
|
||||
{
|
||||
$fileExtThumb = explode('.', $thumbnailFileName);
|
||||
$fileActualExtThumb = strtolower(end($fileExtThumb));
|
||||
|
||||
@@ -49,9 +50,8 @@ function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
|
||||
rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
|
||||
return $thumbnailFileNewName;
|
||||
}else{
|
||||
echo "Wrong file type";
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "Wrong file type thumbnailFile"]);
|
||||
exit();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -17,4 +17,4 @@ if(isset($_GET['gameDataId'])){
|
||||
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 $openGameDataStream->toJson(JSON_PRETTY_PRINT);
|
||||
echo json_encode(array('data' => $openGameDataStream->jsonSerialize()));
|
||||
@@ -37,14 +37,15 @@ if(isLogin()){
|
||||
}
|
||||
$gameData->is_web_Based = $isWebBased;
|
||||
if(!$gameData->save()){
|
||||
http_response_code(500);
|
||||
http_response_code(500);
|
||||
}else{
|
||||
http_response_code(201);
|
||||
http_response_code(201);
|
||||
}
|
||||
|
||||
}else{
|
||||
http_response_code(400);
|
||||
http_response_code(400);
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not login"]);
|
||||
}
|
||||
@@ -58,18 +58,21 @@ if(isLogin()){
|
||||
http_response_code(201);
|
||||
}
|
||||
|
||||
}else{
|
||||
http_response_code(500);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
}
|
||||
}else{
|
||||
echo "Can only upload one file";
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "Can only upload one file"]);
|
||||
}
|
||||
}else{
|
||||
echo "Can only upload when the game jam has started";
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "Can only upload when the game jam has started"]);
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not login"]);
|
||||
}
|
||||
@@ -15,6 +15,7 @@ if(isset($_GET['gameJamId'])){
|
||||
}
|
||||
|
||||
header('Content-Type: application/json;charset=UTF-8');
|
||||
echo $dbValue->toJson(JSON_PRETTY_PRINT);
|
||||
|
||||
echo json_encode(array('data' => $dbValue->jsonSerialize()));
|
||||
|
||||
//var_dump(headers_list());
|
||||
@@ -14,6 +14,9 @@ if(isAdmin()){
|
||||
$gameJam->name = $_POST["gameJamName"];
|
||||
$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()){
|
||||
@@ -27,4 +30,5 @@ if(isAdmin()){
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not admin"]);
|
||||
}
|
||||
@@ -26,10 +26,14 @@ if(isAdmin()){
|
||||
}else{
|
||||
http_response_code(500);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "game jam not found"]);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not admin"]);
|
||||
}
|
||||
|
||||
@@ -15,4 +15,4 @@ else{
|
||||
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 $groups->toJson(JSON_PRETTY_PRINT);
|
||||
echo json_encode(array('data' => $groups->jsonSerialize()));
|
||||
@@ -5,6 +5,7 @@ use Backend\Models\Group;
|
||||
use Backend\Models\Password;
|
||||
session_start();
|
||||
|
||||
|
||||
/**
|
||||
* @param string $token
|
||||
* @return Group|null ;
|
||||
@@ -42,4 +43,15 @@ function passwordValidate(string $password1): bool
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
function makeLogin(string $groupName, int $groupId)
|
||||
{
|
||||
$cookieCon = array(
|
||||
'expires' => 0,
|
||||
'samesite' => 'Strict',
|
||||
'path' => '/'
|
||||
);
|
||||
setcookie("groupName", $groupName, $cookieCon);
|
||||
setcookie("groupId", $groupId, $cookieCon);
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
require "../../../bootstrap.php";
|
||||
require_once "../../../bootstrap.php";
|
||||
require_once "Group.php";
|
||||
|
||||
use Backend\Models\Group;
|
||||
use Backend\Models\Password;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
//Start the php session
|
||||
session_start();
|
||||
|
||||
if(isset($_POST['login'])){
|
||||
|
||||
@@ -22,9 +22,9 @@ if(isset($_POST['login'])){
|
||||
$groupPassword = Password::firstWhere('group_id', $group->id);
|
||||
$groupPassword->remember_token = $token;
|
||||
if($groupPassword->save()){
|
||||
$_SESSION['groupName'] = $groupName;
|
||||
$_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);
|
||||
@@ -37,12 +37,16 @@ if(isset($_POST['login'])){
|
||||
}else{
|
||||
session_destroy();
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "Wrong password"]);
|
||||
}
|
||||
|
||||
}else{
|
||||
session_destroy();
|
||||
http_response_code(400);
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "group was not found"]);
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
|
||||
session_destroy();
|
||||
$cookieCon = array(
|
||||
'expires' => -1,
|
||||
'samesite' => 'Strict',
|
||||
'path' => '/'
|
||||
);
|
||||
setcookie("groupName", null, $cookieCon);
|
||||
setcookie("groupId", null, $cookieCon);
|
||||
setcookie("userName", null, $cookieCon);
|
||||
|
||||
echo http_response_code(200);
|
||||
@@ -18,6 +18,7 @@ if(isAdmin()){
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "group not found"]);
|
||||
}
|
||||
|
||||
}else{
|
||||
@@ -25,4 +26,5 @@ if(isAdmin()){
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not admin"]);
|
||||
}
|
||||
@@ -24,8 +24,10 @@ if(isset($_POST['regGroup'])){
|
||||
$group->group_amount = $_POST['groupAmount'];
|
||||
|
||||
if(!$group->save()){
|
||||
return;
|
||||
http_response_code(500);
|
||||
exit();
|
||||
}
|
||||
|
||||
$password = New Password();
|
||||
|
||||
$password->group()->associate($group);
|
||||
@@ -38,16 +40,19 @@ if(isset($_POST['regGroup'])){
|
||||
|
||||
if(!$password->save()){
|
||||
http_response_code(500);
|
||||
}else{
|
||||
http_response_code(201);
|
||||
exit();
|
||||
}
|
||||
|
||||
$_SESSION['groupName'] = $groupName;
|
||||
$_SESSION['token'] = $token;
|
||||
$_SESSION['success'] = "You are now logged in";
|
||||
makeLogin($groupName,$group->id);
|
||||
http_response_code(201);
|
||||
echo json_encode(["message" => "you are login"]);
|
||||
|
||||
}else{
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "password not valid"]);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
|
||||
@@ -16,11 +16,16 @@ if(isLogin()){
|
||||
http_response_code(201);
|
||||
}
|
||||
}
|
||||
else{
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "group not found"]);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not login"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,10 +14,15 @@ if(isLogin()){
|
||||
http_response_code(201);
|
||||
}
|
||||
}
|
||||
else{
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "password not valid"]);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not login"]);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,13 @@ if(isset($_POST['1Vote'])){
|
||||
}else{
|
||||
http_response_code(201);
|
||||
}
|
||||
} else{
|
||||
http_response_code(403);
|
||||
echo json_encode(["message" => "you have already voted"]);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "you have already voted"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,8 +5,9 @@ require_once "../Group/Group.php";
|
||||
|
||||
if(isLogin()){
|
||||
header('Content-Type: application/json;charset=UTF-8');
|
||||
echo Vote::where('group_id',groupViaToken($_SESSION['token'])->id)->get()->toJson(JSON_PRETTY_PRINT);
|
||||
echo json_encode(array('data' => Vote::where('group_id',groupViaToken($_SESSION['token'])->id)->get()->jsonSerialize()));
|
||||
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "not login"]);
|
||||
}
|
||||
|
||||
@@ -5,30 +5,39 @@ use Backend\Models\Group;
|
||||
use Backend\Models\Vote;
|
||||
use \Illuminate\Support\Collection;
|
||||
|
||||
if(isAdmin() && isset($_GET['gameJamId'])){
|
||||
$groups = Group::where('game_jam_id',$_GET['gameJamId'])->get();
|
||||
$winningGroups = new Collection();
|
||||
$i = -1;
|
||||
foreach ($groups as $group){
|
||||
$x = Vote::where('group_id', $group->id)->count();
|
||||
if($x>$i){
|
||||
if(isAdmin()){
|
||||
if(isset($_GET['gameJamId'])) {
|
||||
$groups = Group::where('game_jam_id', $_GET['gameJamId'])->get();
|
||||
if($groups) {
|
||||
$winningGroups = new Collection();
|
||||
$winningGroups->push($group);
|
||||
$i = -1;
|
||||
foreach ($groups as $group) {
|
||||
$x = Vote::where('group_id', $group->id)->count();
|
||||
if ($x > $i) {
|
||||
$winningGroups = new Collection();
|
||||
$winningGroups->push($group);
|
||||
|
||||
$i = $x;
|
||||
$i = $x;
|
||||
} elseif ($i === $x) {
|
||||
$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');
|
||||
echo json_encode(array('data' => $winningGroups->jsonSerialize()));
|
||||
}
|
||||
elseif ($i === $x){
|
||||
$winningGroups->push($group);
|
||||
else{
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "game jam not found"]);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
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 $winningGroups->toJson(JSON_PRETTY_PRINT);
|
||||
|
||||
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "not admin"]);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,11 @@ if (!isAdmin()){
|
||||
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);
|
||||
echo json_encode(array('data' => $find_all_keywords->jsonSerialize()));
|
||||
}else{
|
||||
http_response_code(400);
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "is not admin"]);
|
||||
}
|
||||
@@ -30,8 +30,8 @@ if (isLogin()) {
|
||||
http_response_code(201);
|
||||
}
|
||||
}else{
|
||||
echo "limited upload reached";
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "limited upload reached"]);
|
||||
}
|
||||
|
||||
}else{
|
||||
@@ -39,5 +39,6 @@ if (isLogin()) {
|
||||
}
|
||||
}else{
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "not login"]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user