Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
@@ -1,20 +1,29 @@
|
||||
$(document).ready(function () {
|
||||
// Register Start
|
||||
let selectedGameJam;
|
||||
let MemberSize = $('#NUDDisplay').text();
|
||||
let isAdminLoggedIn = false;
|
||||
let displayValue = 0;
|
||||
let arr = [
|
||||
{"id": "-1", "Gamejam": "Vælg aktivt GameJam"}
|
||||
];
|
||||
|
||||
if (getCookie('userName') != null)
|
||||
{
|
||||
isAdminLoggedIn = true;
|
||||
SwitchNavInfo(true, true);
|
||||
}
|
||||
else if (getCookie('groupName') != null)
|
||||
{
|
||||
isAdminLoggedIn = false;
|
||||
SwitchNavInfo(true);
|
||||
}
|
||||
|
||||
// Populate select with options from the database
|
||||
axios.get('/Backend/Controllers/GameJam/GetGameJam.php')
|
||||
.then(function(res) {
|
||||
let resArr = res.data.data;
|
||||
|
||||
// console.log(resArr);
|
||||
|
||||
for(let i = 0; i < resArr.length; i++)
|
||||
for(let i = 0; i < res.data.data.length; i++)
|
||||
{
|
||||
arr.push({
|
||||
id: resArr[i].id,
|
||||
@@ -33,8 +42,8 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log(err);
|
||||
.catch(function(error) {
|
||||
console.log(error.response);
|
||||
});
|
||||
|
||||
// Remove invalidInput if selected option has been changed
|
||||
@@ -154,9 +163,12 @@ $(document).ready(function () {
|
||||
axios.post(URL, formData, {
|
||||
header: 'multipart/form-data'
|
||||
}).then(res => {
|
||||
console.log(res);
|
||||
if (res.status === 201)
|
||||
{
|
||||
SwitchNavInfo(true);
|
||||
}
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
console.log(error.response);
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
@@ -216,13 +228,136 @@ $(document).ready(function () {
|
||||
}).then(res => {
|
||||
if (res.status === 200)
|
||||
{
|
||||
console.log('Logged in');
|
||||
}
|
||||
isAdminLoggedIn = false;
|
||||
SwitchNavInfo(true);
|
||||
}
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
if (error.response.status === 401)
|
||||
{
|
||||
$('#loginUsername').css({'border-color':'red'});
|
||||
$('#loginPassword').css({'border-color':'red'});
|
||||
$('#ErrorText').css({'display':'block'});
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log(error.response);
|
||||
}
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
})
|
||||
});
|
||||
|
||||
$('#AdminLoginForm').submit(function(e) {
|
||||
let URL = "/Backend/Controllers/Admin/AdminLogin.php";
|
||||
|
||||
let form = $('#AdminLoginForm')[0];
|
||||
let formData = new FormData(form);
|
||||
|
||||
let id = $('#AdminLoginBtn').attr('name');
|
||||
let value = $('#AdminLoginBtn').val();
|
||||
|
||||
formData.append(id, value);
|
||||
|
||||
axios.post(URL, formData, {
|
||||
header: 'multipart/form-data'
|
||||
}).then(res => {
|
||||
if (res.status === 200)
|
||||
{
|
||||
isAdminLoggedIn = true;
|
||||
SwitchNavInfo(true, true);
|
||||
}
|
||||
}).catch(error => {
|
||||
if (error.response.status === 401)
|
||||
{
|
||||
$('#adminUsername').css({'border-color':'red'});
|
||||
$('#adminPassword').css({'border-color':'red'});
|
||||
$('#AdminErrorText').css({'display':'block'});
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log(error.response);
|
||||
}
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
function SwitchNavInfo(isLoggedIn, isAdmin) {
|
||||
if (isLoggedIn)
|
||||
{
|
||||
$('#NavUser').css({'display':'block'});
|
||||
$('#NavUser').text(`Welcome, ${isAdmin ? getCookie('userName') : getCookie('groupName')}!`);
|
||||
|
||||
$('#NavLogin').css({'display':'none'});
|
||||
$('#NavLogout').css({'display':'block'});
|
||||
|
||||
$('#LoginModal').modal('hide');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#NavUser').css({'display':'none'});
|
||||
$('#NavUser').text(``);
|
||||
|
||||
$('#NavLogin').css({'display':'block'});
|
||||
$('#NavLogout').css({'display':'none'});
|
||||
}
|
||||
|
||||
if (isAdmin === undefined)
|
||||
{
|
||||
return
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isAdmin)
|
||||
{
|
||||
if (isLoggedIn)
|
||||
{
|
||||
$('#AdminPanel').css({'display':'block'});
|
||||
|
||||
console.log('Logged In As Admin!');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#AdminPanel').css({'display':'none'});
|
||||
|
||||
console.log('Logged Out As Admin!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Login end
|
||||
|
||||
// Logout start
|
||||
$('#NavLogout').click(function() {
|
||||
axios.get('/Backend/Controllers/Group/Logout.php').then(res => {
|
||||
if (res.status == 200)
|
||||
{
|
||||
SwitchNavInfo(false, isAdminLoggedIn);
|
||||
isAdminLoggedIn = false;
|
||||
}
|
||||
}).catch(error => {
|
||||
console.log(error.response);
|
||||
});
|
||||
});
|
||||
// Logout end
|
||||
|
||||
function getCookie(name) {
|
||||
// Split cookie string and get all individual name=value pairs in an array
|
||||
var cookieArr = document.cookie.split(";");
|
||||
|
||||
// Loop through the array elements
|
||||
for(var i = 0; i < cookieArr.length; i++) {
|
||||
var cookiePair = cookieArr[i].split("=");
|
||||
|
||||
/* Removing whitespace at the beginning of the cookie name
|
||||
and compare it with the given string */
|
||||
if(name == cookiePair[0].trim()) {
|
||||
// Decode the cookie value and return
|
||||
return decodeURIComponent(cookiePair[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Return null if not found
|
||||
return null;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user