diff --git a/Backend/Controllers/Admin/Admin.php b/Backend/Controllers/Admin/Admin.php
index c394c4a..097b9a2 100644
--- a/Backend/Controllers/Admin/Admin.php
+++ b/Backend/Controllers/Admin/Admin.php
@@ -8,3 +8,12 @@ function isAdmin(): bool
return isset($_SESSION['admin']);
}
+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 813b3dd..08d6a4d 100644
--- a/Backend/Controllers/Admin/AdminLogin.php
+++ b/Backend/Controllers/Admin/AdminLogin.php
@@ -19,6 +19,7 @@ if(isset($_POST['aLogin'])){
$_SESSION['userName'] = $userName;
$_SESSION['admin'] = true;
$_SESSION['success'] = "You are now logged in";
+ makeAdminLogin($userName);
http_response_code(200);
}else{
session_destroy();
diff --git a/Backend/Controllers/Group/Logout.php b/Backend/Controllers/Group/Logout.php
index f8e4552..bf2e3fe 100644
--- a/Backend/Controllers/Group/Logout.php
+++ b/Backend/Controllers/Group/Logout.php
@@ -1,9 +1,10 @@
-1,
'samesite' => 'Strict',
@@ -11,5 +12,6 @@ $cookieCon = array(
);
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/setup.php b/Backend/setup.php
new file mode 100644
index 0000000..1c83ba7
--- /dev/null
+++ b/Backend/setup.php
@@ -0,0 +1,98 @@
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+ }
+ $sql = "CREATE DATABASE ".$DBName;
+ if ($conn->query($sql) === TRUE) {
+ echo "Database created successfully";
+ } else {
+ echo "Error creating database: " . $conn->error;
+ }
+ $conn->close();
+ return array(
+ "driver" => "mysql",
+ "host" => $servername,
+ "database" => $DBName,
+ "username" => $username,
+ "password" => $password
+ );
+}
+
+/**
+ * @param string $DBName
+ * @return string[]
+ */
+function liteDB(string $DBName): array
+{
+ New SQLite3("Database/".$DBName.".sqlite");
+ $test = array(
+ 'driver' => 'sqlite',
+ 'database' => realpath(dirname(__FILE__)."/Database/".$DBName.".sqlite")
+ //'Backend/Database/'.$DBName.'.sqlite'
+ );
+ var_dump($test);
+ return $test;
+}
+
+
+$servername = "localhost";
+$username = "root";
+$password = "V#_xWL6_";
+$DBName = "TestDB";
+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:
+ die("wrong dbType");
+ }
+
+ file_put_contents("../config/database.json", json_encode($dbCon));
+
+ require_once('../bootstrap.php');
+ try{
+ $capsule->Connection()->getPdo();
+ } catch (\Exception $e) {
+ //file_put_contents("../config/database.json", NULL);
+ die("Could not connect to the database. Please check your configuration. error:" . $e );
+ }
+ require_once ('Database/databaseMigration.php');
+ AdminUser::firstOrCreate([
+ 'user_name' => $_POST["AdminUsername"], 'password' => password_hash($_POST["AdminPassword"],PASSWORD_DEFAULT)
+ ]);
+
+
+
+}else{
+ echo "not set";
+
+}
+
+
+
+
+
+
diff --git a/Frontend/Html/AdminPage.html b/Frontend/Html/AdminPage.html
index 3e3a9f2..b99939b 100755
--- a/Frontend/Html/AdminPage.html
+++ b/Frontend/Html/AdminPage.html
@@ -28,6 +28,11 @@
+
+
+
+
+
@@ -129,7 +133,9 @@
+
+
diff --git a/Frontend/Javascript/LoginFunctionality.js b/Frontend/Javascript/LoginFunctionality.js
index 5c19cfc..e1698d2 100755
--- a/Frontend/Javascript/LoginFunctionality.js
+++ b/Frontend/Javascript/LoginFunctionality.js
@@ -1,28 +1,36 @@
$(document).ready(function () {
- // Register Start
let selectedGameJam;
- let MemberSize = $('#NUDDisplay').text();
let displayValue = 0;
- let arr = [
+ let AvailableJams = [
{"id": "-1", "Gamejam": "Vælg aktivt GameJam"}
];
+ let GroupName = getCookie('groupName');
+ let GroupId = getCookie('groupId');
+
+ // Control Logged in users
+ if (GroupId != null)
+ {
+ LoggedInUser();
+ }
+ //
+
+ // Register Start
+
// Populate select with options from the database
axios.get('/Backend/Controllers/GameJam/GetGameJam.php')
.then(function(res) {
- let resArr = res.data;
+ let resArr = res.data.data;
- //console.log(res.data.data);
-
- for(let i = 0; i < res.data.data.length; i++)
+ for(let i = 0; i < resArr.length; i++)
{
- arr.push({
- id: res.data.data[i].id,
- Gamejam: res.data.data[i].name
+ AvailableJams.push({
+ id: resArr[i].id,
+ Gamejam: resArr[i].name
});
}
- $.each(arr, function(i, data) {
+ $.each(AvailableJams, function(i, data) {
if (i === 0)
{
$('#GameJamSelect').append('');
@@ -154,7 +162,15 @@ $(document).ready(function () {
axios.post(URL, formData, {
header: 'multipart/form-data'
}).then(res => {
- console.log(res);
+ if (res.status == 201)
+ {
+ let LoginModalElem = document.getElementById('LoginModal')
+ let LoginModal = bootstrap.Modal.getInstance(LoginModalElem);
+
+ LoginModal.hide();
+
+ LoggedInUser();
+ }
}).catch(error => {
console.log(error);
});
@@ -189,20 +205,14 @@ $(document).ready(function () {
$('#NUDDisplay').text(displayValue);
}
});
-
-
- async function GetGroupNames() {
- const res = await axios.get('/Backend/Controllers/Group/GetGroup.php');
-
- return res.data;
- }
-
// Register end
// Login start
$('#LoginForm').submit(function(e) {
let URL = "/Backend/Controllers/Group/Login.php";
+ $('#loginUsername').attr('name') = "groupName";
+
let form = $('#LoginForm')[0];
let formData = new FormData(form);
@@ -211,13 +221,17 @@ $(document).ready(function () {
formData.append(id, value);
-
axios.post(URL, formData, {
header: 'multipart/form-data'
}).then(res => {
if (res.status === 200)
{
- console.log('Logged in');
+ let LoginModalElem = document.getElementById('LoginModal')
+ let LoginModal = bootstrap.Modal.getInstance(LoginModalElem);
+
+ LoginModal.hide();
+
+ LoggedInUser();
}
}).catch(error => {
console.log(error);
@@ -226,4 +240,94 @@ $(document).ready(function () {
e.preventDefault();
})
// Login end
+
+ // Admin Login Start
+ $('#AdminLoginBtn').submit(function(e) {
+ let URL = "/Backend/Controllers/Admin/AdminLogin.php";
+
+ $('#loginUsername').attr('name') = "userName";
+
+ let form = $('#LoginForm')[0];
+ let formData = new FormData(form);
+
+ let id = $('#LoginBtn').attr('name');
+ let value = $('#LoginBtn').val();
+
+ formData.append(id, value);
+
+ axios.post(URL, formData, {
+ header: 'multipart/form-data'
+ }).then(res => {
+ if (res.status === 200)
+ {
+ let LoginModalElem = document.getElementById('LoginModal')
+ let LoginModal = bootstrap.Modal.getInstance(LoginModalElem);
+
+ LoginModal.hide();
+
+ LoggedInUser();
+ }
+ }).catch(error => {
+ console.log(error);
+ });
+
+ e.preventDefault();
+ });
+ // Admin Login End
+
+ // Logout Start
+ $('#UserLogout').click(function() {
+ axios.get('/Backend/Controllers/Group/Logout.php').then(res => {
+ if(res.status === 200)
+ {
+ UserLoggedOut();
+ }
+ }).catch(error => {
+ console.log(error);
+ });
+ });
+ // Logout End
+
+ // Functions Start
+ function LoggedInUser() {
+ $('#NavLogin').css({
+ "display": "none"
+ });
+
+ $('#UserLogout').css({
+ "display": "block"
+ });
+
+ $('#NavUser').text(`Logget ind som: ${GroupName}`);
+ $('#NavUser').css({
+ "display": "block"
+ });
+ }
+
+ function UserLoggedOut() {
+ $('#NavLogin').css({
+ "display": "block"
+ });
+
+ $('#UserLogout').css({
+ "display": "None"
+ });
+
+ $('#NavUser').css({
+ "display": "none"
+ });
+ }
+
+ async function GetGroupNames() {
+ const res = await axios.get('/Backend/Controllers/Group/GetGroup.php');
+
+ return res.data;
+ }
+
+ function getCookie(name) {
+ const value = `; ${document.cookie}`;
+ const parts = value.split(`; ${name}=`);
+ if (parts.length === 2) return parts.pop().split(';').shift();
+ }
+ // Functions End
});
\ No newline at end of file
diff --git a/Frontend/Javascript/qweData.js b/Frontend/Javascript/qweData.js
new file mode 100755
index 0000000..2770f4c
--- /dev/null
+++ b/Frontend/Javascript/qweData.js
@@ -0,0 +1,19 @@
+$(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);
+ }
+ });
+}
+
+
+
+//console.log(result.name); ?gameJamId=1
+//console.log(result[0].name); uden ?gameJamId=1
\ No newline at end of file
diff --git a/Frontend/Styles/Index.css b/Frontend/Styles/Index.css
index a2d948e..589ff44 100755
--- a/Frontend/Styles/Index.css
+++ b/Frontend/Styles/Index.css
@@ -118,11 +118,15 @@ a:hover {
margin: 1vw 10vw 0;
}
-.LoginButton {
+.RightNavText {
+ color: rgba(255, 255, 255, .75);
+}
+
+.RightNavButton {
color: rgba(255, 255, 255, .55);
}
-.LoginButton:hover {
+.RightNavButton:hover {
color: rgba(255, 255, 255, .75);
}
@@ -259,7 +263,7 @@ a:hover {
.modal-body {
padding: 0 0;
- margin: 2vh 2vw;
+ margin: 1vh 1vw;
background-color: rgb(18, 18, 18);
}
@@ -470,11 +474,12 @@ a:hover {
color: rgba(255, 255, 255, .75);
}
-.box input[type="submit"] {
+.box #LoginBtn,
+.box #RegisterBtn {
border: 0;
background: none;
display: block;
- margin: 20px auto;
+ margin: 20px auto 0 auto;
text-align: center;
border: 2px solid rgb(46, 204, 113);
padding: 14px 40px;
@@ -485,7 +490,22 @@ a:hover {
cursor: pointer;
}
-.box input[type="submit"]:hover {
+.box #AdminLoginBtn {
+ border: 0;
+ background: transparent;
+ color: rgba(255, 255, 255, .55);
+ display: block;
+ margin: 0 auto;
+ text-align: center;
+ padding: 14px 10px;
+ outline: none;
+ border-radius: 24px;
+ transition: 0.25s;
+ cursor: pointer;
+}
+
+.box #LoginBtn:hover,
+.box #RegisterBtn:hover {
background: rgb(46, 204, 113);
color: rgba(255, 255, 255, .75);
}
diff --git a/composer.lock b/composer.lock
index 0b2ef39..e14538e 100755
--- a/composer.lock
+++ b/composer.lock
@@ -103,16 +103,16 @@
},
{
"name": "illuminate/collections",
- "version": "v8.32.1",
+ "version": "v8.34.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/collections.git",
- "reference": "d7cc717a00064b40fa63a8ad522042005e1de1ed"
+ "reference": "e18d6e4cf03dd597bc3ecd86fefc2023d0c7a5e8"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/collections/zipball/d7cc717a00064b40fa63a8ad522042005e1de1ed",
- "reference": "d7cc717a00064b40fa63a8ad522042005e1de1ed",
+ "url": "https://api.github.com/repos/illuminate/collections/zipball/e18d6e4cf03dd597bc3ecd86fefc2023d0c7a5e8",
+ "reference": "e18d6e4cf03dd597bc3ecd86fefc2023d0c7a5e8",
"shasum": ""
},
"require": {
@@ -153,20 +153,20 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2021-03-08T17:22:22+00:00"
+ "time": "2021-03-19T00:05:33+00:00"
},
{
"name": "illuminate/container",
- "version": "v8.32.1",
+ "version": "v8.34.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/container.git",
- "reference": "3d6ce613f455093fdf8bd3c81b30104aef0b11e0"
+ "reference": "0e38ee1632d470e56aece0079e6e22d13e6bea8e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/container/zipball/3d6ce613f455093fdf8bd3c81b30104aef0b11e0",
- "reference": "3d6ce613f455093fdf8bd3c81b30104aef0b11e0",
+ "url": "https://api.github.com/repos/illuminate/container/zipball/0e38ee1632d470e56aece0079e6e22d13e6bea8e",
+ "reference": "0e38ee1632d470e56aece0079e6e22d13e6bea8e",
"shasum": ""
},
"require": {
@@ -204,20 +204,20 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2021-02-12T21:15:27+00:00"
+ "time": "2021-03-16T19:42:20+00:00"
},
{
"name": "illuminate/contracts",
- "version": "v8.32.1",
+ "version": "v8.34.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/contracts.git",
- "reference": "9c7a9868d7485a82663d67109429094c8e4ed56d"
+ "reference": "121cea1d8b8772bc7fee99c71ecf0f57c1d77b3b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/contracts/zipball/9c7a9868d7485a82663d67109429094c8e4ed56d",
- "reference": "9c7a9868d7485a82663d67109429094c8e4ed56d",
+ "url": "https://api.github.com/repos/illuminate/contracts/zipball/121cea1d8b8772bc7fee99c71ecf0f57c1d77b3b",
+ "reference": "121cea1d8b8772bc7fee99c71ecf0f57c1d77b3b",
"shasum": ""
},
"require": {
@@ -252,20 +252,20 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2021-02-26T13:17:03+00:00"
+ "time": "2021-03-12T14:45:30+00:00"
},
{
"name": "illuminate/database",
- "version": "v8.32.1",
+ "version": "v8.34.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/database.git",
- "reference": "f6a10cebd9bbd188ca66993168fb453439dbb50f"
+ "reference": "74a165fd07b36cc0ea3558fa391b762867af87e8"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/database/zipball/f6a10cebd9bbd188ca66993168fb453439dbb50f",
- "reference": "f6a10cebd9bbd188ca66993168fb453439dbb50f",
+ "url": "https://api.github.com/repos/illuminate/database/zipball/74a165fd07b36cc0ea3558fa391b762867af87e8",
+ "reference": "74a165fd07b36cc0ea3558fa391b762867af87e8",
"shasum": ""
},
"require": {
@@ -320,11 +320,11 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2021-03-09T14:06:15+00:00"
+ "time": "2021-03-23T15:12:51+00:00"
},
{
"name": "illuminate/macroable",
- "version": "v8.32.1",
+ "version": "v8.34.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/macroable.git",
@@ -370,16 +370,16 @@
},
{
"name": "illuminate/support",
- "version": "v8.32.1",
+ "version": "v8.34.0",
"source": {
"type": "git",
"url": "https://github.com/illuminate/support.git",
- "reference": "2ef7ff288366a1ebe32f633196a1b90bd443acc3"
+ "reference": "b7b27e758b68aad44558c62e7374328835895386"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/illuminate/support/zipball/2ef7ff288366a1ebe32f633196a1b90bd443acc3",
- "reference": "2ef7ff288366a1ebe32f633196a1b90bd443acc3",
+ "url": "https://api.github.com/repos/illuminate/support/zipball/b7b27e758b68aad44558c62e7374328835895386",
+ "reference": "b7b27e758b68aad44558c62e7374328835895386",
"shasum": ""
},
"require": {
@@ -434,7 +434,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2021-03-05T15:22:14+00:00"
+ "time": "2021-03-21T13:37:37+00:00"
},
{
"name": "nesbot/carbon",
diff --git a/config/database.json b/config/database.json
new file mode 100644
index 0000000..e69de29