From 029bc3c67ddef6c4554f4977f595b30948cdd800 Mon Sep 17 00:00:00 2001 From: Minik Gaarde Lambrecht Date: Mon, 22 Mar 2021 15:29:18 +0100 Subject: [PATCH] Login Functionality Update --- .htaccess | 2 + .../Controllers/FileHandler/GetGameData.php | 2 +- Backend/Controllers/GameJam/GetGameJam.php | 3 +- Backend/Controllers/Group/GetGroup.php | 2 +- Backend/Controllers/Polls/GetVote.php | 2 +- Backend/Controllers/Polls/GetWinner.php | 2 +- Backend/Controllers/keyWord/GetKeyWinner.php | 2 +- Frontend/Index.html | 14 ++++--- Frontend/Javascript/LoginFunctionality.js | 29 ++++++++++++++ Frontend/Javascript/qweData.js | 40 ------------------- bootstrap.php | 8 ++-- 11 files changed, 50 insertions(+), 56 deletions(-) create mode 100644 .htaccess create mode 100644 Frontend/Javascript/LoginFunctionality.js delete mode 100644 Frontend/Javascript/qweData.js diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..d044b84 --- /dev/null +++ b/.htaccess @@ -0,0 +1,2 @@ +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/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/GameJam/GetGameJam.php b/Backend/Controllers/GameJam/GetGameJam.php index 1dd4d1b..29b6bbd 100644 --- a/Backend/Controllers/GameJam/GetGameJam.php +++ b/Backend/Controllers/GameJam/GetGameJam.php @@ -12,6 +12,7 @@ if(isset($_GET['gameJamId'])){ 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 $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/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/Polls/GetVote.php b/Backend/Controllers/Polls/GetVote.php index 162b1f5..78ca37a 100644 --- a/Backend/Controllers/Polls/GetVote.php +++ b/Backend/Controllers/Polls/GetVote.php @@ -5,7 +5,7 @@ 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{ echo http_response_code(401); diff --git a/Backend/Controllers/Polls/GetWinner.php b/Backend/Controllers/Polls/GetWinner.php index 5fbf44d..06fa051 100644 --- a/Backend/Controllers/Polls/GetWinner.php +++ b/Backend/Controllers/Polls/GetWinner.php @@ -25,7 +25,7 @@ if(isAdmin() && isset($_GET['gameJamId'])){ 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); + echo json_encode(array('data' => $winningGroups->jsonSerialize())); }else{ diff --git a/Backend/Controllers/keyWord/GetKeyWinner.php b/Backend/Controllers/keyWord/GetKeyWinner.php index ed3e80a..b009a63 100644 --- a/Backend/Controllers/keyWord/GetKeyWinner.php +++ b/Backend/Controllers/keyWord/GetKeyWinner.php @@ -23,7 +23,7 @@ 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{ echo http_response_code(400); } diff --git a/Frontend/Index.html b/Frontend/Index.html index bdd9eeb..2f3be15 100644 --- a/Frontend/Index.html +++ b/Frontend/Index.html @@ -17,6 +17,7 @@ + @@ -134,11 +135,12 @@ -
- - + + +
+ + +
@@ -632,7 +634,7 @@ - + diff --git a/Frontend/Javascript/LoginFunctionality.js b/Frontend/Javascript/LoginFunctionality.js new file mode 100644 index 0000000..68461df --- /dev/null +++ b/Frontend/Javascript/LoginFunctionality.js @@ -0,0 +1,29 @@ +$(document).ready(function() { + // Populate select with GameJams + let JamArr = []; + + axios.get('/Backend/Controllers/GameJam/GetGameJam.php').then(res => { + let resArr = res.data; + + for(let i = 0; i < resArr.data.length; i++) + { + let Jam = resArr.data[i]; + JamArr.push({ + id: Jam.id, + Name: Jam.name + }); + } + + $.each(JamArr, function(i, Jam) { + console.log(`Id: ${Jam.id} \n Name: ${Jam.Name}`); + if(i === 1) + { + $('#AvailableGameJams').append(''); + } + + $('#AvailableGameJams').append(''); + }) + }).catch(error => { + console.log(`Error: ${error}`) + }); +}); \ No newline at end of file diff --git a/Frontend/Javascript/qweData.js b/Frontend/Javascript/qweData.js deleted file mode 100644 index 1f7e414..0000000 --- a/Frontend/Javascript/qweData.js +++ /dev/null @@ -1,40 +0,0 @@ -/* -$(window).on("load", function(){ - dataFetch(); -}); - - - -function dataFetch(){ - $.ajax({ - type: "GET", - url: "/Game-Jaming/Backend/controllers/GameJam/GetGameJam.php", - success: function(result){ - console.log(result[0].name); - } - }); -} - */ - - -$("#qweLog").click(function(){ - var vgroupName = $("#groupName").val(); - var vpassword = $("#groupPassword").val(); - - $.post("/Game-Jaming/Backend/Controllers/Group/Login.php", - { - login: "data", - groupName: vgroupName, - password: vpassword - }, - function(data){ - alert("Data: " + data); - }); -}); - - - - - -//console.log(result.name); ?gameJamId=1 -//console.log(result[0].name); uden ?gameJamId=1 \ No newline at end of file diff --git a/bootstrap.php b/bootstrap.php index a09eca2..2da690d 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -4,10 +4,10 @@ use Illuminate\Database\Capsule\Manager as Capsule; $capsule = new Capsule; $capsule->addConnection([ "driver" => "mysql", - "host" =>"127.0.0.1", - "database" => "gamejamdb", + "host" =>"localhost", + "database" => "TestDB", "username" => "root", - "password" => "" + "password" => "V#_xWL6_" ]); $capsule->setAsGlobal(); -$capsule->bootEloquent(); \ No newline at end of file +$capsule->bootEloquent();