diff --git a/.gitignore b/.gitignore
old mode 100644
new mode 100755
diff --git a/.htaccess b/.htaccess
index 5d497f7..d044b84 100755
--- a/.htaccess
+++ b/.htaccess
@@ -1 +1,2 @@
-Header set Access-Control-Allow-Origin: *
+Header add Access-Control-Allow-Origin "*"
+Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
old mode 100644
new mode 100755
diff --git a/.idea/Game-Jaming.iml b/.idea/Game-Jaming.iml
old mode 100644
new mode 100755
diff --git a/.idea/misc.xml b/.idea/misc.xml
old mode 100644
new mode 100755
diff --git a/.idea/modules.xml b/.idea/modules.xml
old mode 100644
new mode 100755
diff --git a/.idea/php.xml b/.idea/php.xml
old mode 100644
new mode 100755
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
old mode 100644
new mode 100755
diff --git a/Backend/CheckSetup.php b/Backend/CheckSetup.php
new file mode 100644
index 0000000..7d0b919
--- /dev/null
+++ b/Backend/CheckSetup.php
@@ -0,0 +1,11 @@
+ false]);
+}elseif(0 === filesize('../config/database.json')){
+ echo json_encode(['data' => false]);
+}else{
+ echo json_encode(['data' => true]);
+}
diff --git a/Backend/Controllers/Admin/Admin.php b/Backend/Controllers/Admin/Admin.php
index c394c4a..51232d5 100644
--- a/Backend/Controllers/Admin/Admin.php
+++ b/Backend/Controllers/Admin/Admin.php
@@ -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' => '/'
+ ]);
+}
+
diff --git a/Backend/Controllers/Admin/AdminLogin.php b/Backend/Controllers/Admin/AdminLogin.php
index d15b39f..f7ec881 100644
--- a/Backend/Controllers/Admin/AdminLogin.php
+++ b/Backend/Controllers/Admin/AdminLogin.php
@@ -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);
diff --git a/Backend/Controllers/Admin/AdminSignup.php b/Backend/Controllers/Admin/AdminSignup.php
index e47089b..f63eab9 100644
--- a/Backend/Controllers/Admin/AdminSignup.php
+++ b/Backend/Controllers/Admin/AdminSignup.php
@@ -19,4 +19,5 @@ if (isAdmin()){
}
}else{
http_response_code(401);
+ echo json_encode(["message" => "is not admin"]);
}
\ No newline at end of file
diff --git a/Backend/Controllers/FileHandler/FileHandler.php b/Backend/Controllers/FileHandler/FileHandler.php
index cbd439f..e31cb14 100644
--- a/Backend/Controllers/FileHandler/FileHandler.php
+++ b/Backend/Controllers/FileHandler/FileHandler.php
@@ -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;
}
\ No newline at end of file
diff --git a/Backend/Controllers/FileHandler/GetGameData.php b/Backend/Controllers/FileHandler/GetGameData.php
index 01445c6..b58f35c 100644
--- a/Backend/Controllers/FileHandler/GetGameData.php
+++ b/Backend/Controllers/FileHandler/GetGameData.php
@@ -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);
\ No newline at end of file
+echo json_encode(array('data' => $openGameDataStream->jsonSerialize()));
\ No newline at end of file
diff --git a/Backend/Controllers/FileHandler/updateFiles.php b/Backend/Controllers/FileHandler/updateFiles.php
index 3a1e649..b903190 100644
--- a/Backend/Controllers/FileHandler/updateFiles.php
+++ b/Backend/Controllers/FileHandler/updateFiles.php
@@ -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"]);
}
\ No newline at end of file
diff --git a/Backend/Controllers/FileHandler/upload.php b/Backend/Controllers/FileHandler/upload.php
index cea1698..c6cad0c 100644
--- a/Backend/Controllers/FileHandler/upload.php
+++ b/Backend/Controllers/FileHandler/upload.php
@@ -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"]);
}
\ No newline at end of file
diff --git a/Backend/Controllers/GameJam/GetGameJam.php b/Backend/Controllers/GameJam/GetGameJam.php
index e36a06a..6746672 100644
--- a/Backend/Controllers/GameJam/GetGameJam.php
+++ b/Backend/Controllers/GameJam/GetGameJam.php
@@ -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());
\ No newline at end of file
diff --git a/Backend/Controllers/GameJam/NewGameJam.php b/Backend/Controllers/GameJam/NewGameJam.php
index f8bf5fb..f5bdfab 100644
--- a/Backend/Controllers/GameJam/NewGameJam.php
+++ b/Backend/Controllers/GameJam/NewGameJam.php
@@ -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"]);
}
\ No newline at end of file
diff --git a/Backend/Controllers/GameJam/UpdateGameJam.php b/Backend/Controllers/GameJam/UpdateGameJam.php
index b63ec20..6fb62ce 100644
--- a/Backend/Controllers/GameJam/UpdateGameJam.php
+++ b/Backend/Controllers/GameJam/UpdateGameJam.php
@@ -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"]);
}
diff --git a/Backend/Controllers/Group/GetGroup.php b/Backend/Controllers/Group/GetGroup.php
index 1b1203d..e4dee59 100644
--- a/Backend/Controllers/Group/GetGroup.php
+++ b/Backend/Controllers/Group/GetGroup.php
@@ -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);
\ No newline at end of file
+echo json_encode(array('data' => $groups->jsonSerialize()));
\ No newline at end of file
diff --git a/Backend/Controllers/Group/Group.php b/Backend/Controllers/Group/Group.php
index da36077..2519cdf 100644
--- a/Backend/Controllers/Group/Group.php
+++ b/Backend/Controllers/Group/Group.php
@@ -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);
}
\ No newline at end of file
diff --git a/Backend/Controllers/Group/Login.php b/Backend/Controllers/Group/Login.php
index 3d18dc6..f78693d 100644
--- a/Backend/Controllers/Group/Login.php
+++ b/Backend/Controllers/Group/Login.php
@@ -1,13 +1,13 @@
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);
}
diff --git a/Backend/Controllers/Group/Logout.php b/Backend/Controllers/Group/Logout.php
index ac9b642..fa7cbb1 100644
--- a/Backend/Controllers/Group/Logout.php
+++ b/Backend/Controllers/Group/Logout.php
@@ -1,5 +1,16 @@
-1,
+ 'samesite' => 'Strict',
+ 'path' => '/'
+);
+setcookie("groupName", null, $cookieCon);
+setcookie("groupId", null, $cookieCon);
+setcookie("userName", null, $cookieCon);
+
+echo http_response_code(200);
\ No newline at end of file
diff --git a/Backend/Controllers/Group/ResetPassword.php b/Backend/Controllers/Group/ResetPassword.php
index 4ad3cd7..3fa3e8e 100644
--- a/Backend/Controllers/Group/ResetPassword.php
+++ b/Backend/Controllers/Group/ResetPassword.php
@@ -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"]);
}
\ No newline at end of file
diff --git a/Backend/Controllers/Group/SigningUp.php b/Backend/Controllers/Group/SigningUp.php
index b3cd946..40101bc 100644
--- a/Backend/Controllers/Group/SigningUp.php
+++ b/Backend/Controllers/Group/SigningUp.php
@@ -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);
diff --git a/Backend/Controllers/Group/UpdateGruop.php b/Backend/Controllers/Group/UpdateGruop.php
index b96c655..0c2dc5f 100644
--- a/Backend/Controllers/Group/UpdateGruop.php
+++ b/Backend/Controllers/Group/UpdateGruop.php
@@ -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"]);
}
diff --git a/Backend/Controllers/Group/UpdatePassword.php b/Backend/Controllers/Group/UpdatePassword.php
index 3bcd2a9..ea686f2 100644
--- a/Backend/Controllers/Group/UpdatePassword.php
+++ b/Backend/Controllers/Group/UpdatePassword.php
@@ -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"]);
}
diff --git a/Backend/Controllers/Polls/1vote.php b/Backend/Controllers/Polls/1vote.php
index 04ff428..f718230 100644
--- a/Backend/Controllers/Polls/1vote.php
+++ b/Backend/Controllers/Polls/1vote.php
@@ -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"]);
}
diff --git a/Backend/Controllers/Polls/GetVote.php b/Backend/Controllers/Polls/GetVote.php
index e421407..f44593f 100644
--- a/Backend/Controllers/Polls/GetVote.php
+++ b/Backend/Controllers/Polls/GetVote.php
@@ -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"]);
}
diff --git a/Backend/Controllers/Polls/GetWinner.php b/Backend/Controllers/Polls/GetWinner.php
index 3613331..28f597d 100644
--- a/Backend/Controllers/Polls/GetWinner.php
+++ b/Backend/Controllers/Polls/GetWinner.php
@@ -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"]);
}
diff --git a/Backend/Controllers/keyWord/GetKeyWinner.php b/Backend/Controllers/keyWord/GetKeyWinner.php
index 0045d10..3290ed5 100644
--- a/Backend/Controllers/keyWord/GetKeyWinner.php
+++ b/Backend/Controllers/keyWord/GetKeyWinner.php
@@ -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"]);
}
\ No newline at end of file
diff --git a/Backend/Controllers/keyWord/NewKeyWord.php b/Backend/Controllers/keyWord/NewKeyWord.php
index 5049f3b..26aeb7f 100644
--- a/Backend/Controllers/keyWord/NewKeyWord.php
+++ b/Backend/Controllers/keyWord/NewKeyWord.php
@@ -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"]);
}
diff --git a/Backend/setup.php b/Backend/setup.php
new file mode 100644
index 0000000..289514a
--- /dev/null
+++ b/Backend/setup.php
@@ -0,0 +1,111 @@
+connect_error) {
+ http_response_code(400);
+ echo json_encode(["message" => $conn->connect_error]);
+ exit();
+ }
+ $sql = "CREATE DATABASE ".$DBName;
+ if ($conn->query($sql) === FALSE) {
+ http_response_code(400);
+ echo json_encode(["message" => $conn->error]);
+ exit();
+ }
+ $conn->close();
+ return array(
+ "driver" => "mysql",
+ "host" => $servername,
+ "database" => $DBName,
+ "username" => $username,
+ "password" => $password
+ );
+}
+
+/**
+ * @param string $DBName
+ * @return string[]
+ */
+function liteDB(string $DBName): array
+{
+ $DBName = $DBName.".sqlite";
+ if(file_exists($DBName)){
+ http_response_code(400);
+ echo json_encode(["message" => "database already exits"]);
+ exit();
+ }
+ New SQLite3($DBName);
+ return array(
+ 'driver' => 'sqlite',
+ 'database' => realpath(dirname(__FILE__)."/".$DBName)
+ );
+}
+
+$conFilePath = '../config/database.json';
+if(!file_exists($conFilePath)){
+ $confile = fopen($conFilePath, "w");
+ fclose($confile);
+}
+if (0 !== filesize($conFilePath)){
+ http_response_code(400);
+ echo json_encode(["message" => "already have database connection"]);
+ exit();
+}
+
+
+if(isset($_POST["dbSetup"])){
+
+ switch($_POST["dbType"]){
+ case "mysql":
+ $dbCon = myDB($_POST["dbServername"],$_POST["dbUsername"],$_POST["dbPassword"], $_POST["dbName"]);
+ break;
+ case "sqlite":
+ $dbCon = liteDB($_POST["dbName"]);
+ break;
+ default:
+ http_response_code(400);
+ echo json_encode(["message" => "database type is wrong"]);
+ exit();
+ }
+
+ file_put_contents($conFilePath, json_encode($dbCon));
+
+ require_once('../bootstrap.php');
+ try{
+ $capsule->Connection()->getPdo();
+ } catch (\Exception $e) {
+ http_response_code(400);
+ file_put_contents($conFilePath, NULL);
+ echo json_encode(["message" => "Could not connect to the database. Please check your configuration. error:" . $e]);
+ exit();
+ }
+ require_once ('Database/databaseMigration.php');
+ AdminUser::firstOrCreate([
+ 'user_name' => $_POST["AdminUsername"], 'password' => password_hash($_POST["AdminPassword"],PASSWORD_DEFAULT)
+ ]);
+ http_response_code(201);
+
+}else{
+ http_response_code(400);
+}
+
+
+
+
+
+
diff --git a/Frontend/.vs/Frontend/config/applicationhost.config b/Frontend/.vs/Frontend/config/applicationhost.config
new file mode 100644
index 0000000..f7beb9b
--- /dev/null
+++ b/Frontend/.vs/Frontend/config/applicationhost.config
@@ -0,0 +1,1023 @@
+
+
+