diff --git a/scripts/client/public/assets/images/hehe.PNG b/scripts/client/public/assets/images/hehe.PNG deleted file mode 100644 index 2851278effacabd49bc13a360b14ce3fd8b97436..0000000000000000000000000000000000000000 Binary files a/scripts/client/public/assets/images/hehe.PNG and /dev/null differ diff --git a/scripts/client/public/js/admin-product-create.js b/scripts/client/public/js/admin-product-create.js index 3fdf3e675be719e5528c8cad796b9a43144c68c9..46074a9948aba19475d7d32bcfe0e7c6c8f6eadd 100644 --- a/scripts/client/public/js/admin-product-create.js +++ b/scripts/client/public/js/admin-product-create.js @@ -1,6 +1,10 @@ window.onload = function () { infoNavbarAdded(); + setDropdownCategory(); + validateAdmin(); +} +function validateAdmin() { // Check role var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { @@ -16,12 +20,7 @@ window.onload = function () { }; xhttp.open("GET","http://localhost:8000/api/Auth/isAdmin",true); - xhttp.setRequestHeader("Accept", "application/json"); - xhttp.setRequestHeader("Content-Type", "application/json"); - xhttp.withCredentials = true; xhttp.send(); - - setDropdownCategory(); } let setDropdownCategory = async () => { diff --git a/scripts/client/public/js/admin-product-edit.js b/scripts/client/public/js/admin-product-edit.js index d763e51c93b141bc6bb2db8975ddf31f3f65ea80..42b56c9a8b4a7890d1df700f27d82b7cff92edba 100644 --- a/scripts/client/public/js/admin-product-edit.js +++ b/scripts/client/public/js/admin-product-edit.js @@ -3,7 +3,11 @@ let id = urlParams.get("id"); window.onload = async () => { infoNavbarAdded(); + getProductById(id); + validateAdmin(); +}; +function validateAdmin() { // Check role var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { @@ -19,13 +23,8 @@ window.onload = async () => { }; xhttp.open("GET","http://localhost:8000/api/Auth/isAdmin",true); - xhttp.setRequestHeader("Accept", "application/json"); - xhttp.setRequestHeader("Content-Type", "application/json"); - xhttp.withCredentials = true; xhttp.send(); - - getProductById(id); -}; +} let getProductById = async (id) => { let xhr = new XMLHttpRequest(); diff --git a/scripts/client/public/js/admin-product.js b/scripts/client/public/js/admin-product.js index 40c35971074291ebb6495f06dc3ae98d43185c7d..e4ad6e7dbf2ef1a98e65a4c4f44fe4206c297b7d 100644 --- a/scripts/client/public/js/admin-product.js +++ b/scripts/client/public/js/admin-product.js @@ -77,10 +77,6 @@ let getProductsByPage = async (page) => { } else { alert('Failed to get products!'); } - } else { - var errorData = JSON.parse(xhr.responseText); - alert(errorData.message); - window.location.href = errorData.location; } } } @@ -116,10 +112,6 @@ let setPagination = async (page) => { } else { alert('Failed to get pagination!'); } - } else { - var errorData = JSON.parse(xhr.responseText); - alert(errorData.message); - window.location.href = errorData.location; } } } diff --git a/scripts/client/public/js/admin-top-up-create.js b/scripts/client/public/js/admin-top-up-create.js index 61f44d393375e32b3e073d91eb09cc5fc02e9529..dbcaac96d2c0507fa265ca3870a6da3ebde2f7f2 100644 --- a/scripts/client/public/js/admin-top-up-create.js +++ b/scripts/client/public/js/admin-top-up-create.js @@ -2,6 +2,27 @@ const TOP_UP_STATUS = ["Pending", "Approved", "Rejected"]; window.onload = async function () { infoNavbarAdded(); + + // Check role + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4) { + if (this.status == 200) { + console.log(this.responseText); + } else { + var errorData = JSON.parse(xhttp.responseText); + alert(errorData.message); + window.location.href = errorData.location; + } + } + }; + + xhttp.open("GET","http://localhost:8000/api/Auth/isAdmin",true); + xhttp.setRequestHeader("Accept", "application/json"); + xhttp.setRequestHeader("Content-Type", "application/json"); + xhttp.withCredentials = true; + xhttp.send(); + setDropdownStatus(); };