ADMIN UI DONE

This commit is contained in:
andrei-mihnea-cerbu
2024-04-03 05:57:01 +03:00
parent 5e4a488bfd
commit 5e5bab933b
15 changed files with 229 additions and 13 deletions
+1
View File
@@ -23,6 +23,7 @@ enable routing to the server;
so also make sure to open those ports as well;
- If the CEO wants to change the email address linked to the account, his password will be changed
to a low-risk password, so make sure after any release to specify the account information;
- Make sure that all the ports configurations are respected to have all the applications work properly
Closing thoughts
-
+1
View File
@@ -1,4 +1,5 @@
{
"id": "deee8837-3549-44d5-af56-fb7532505574",
"name": "Andrei",
"email": "admin@yourfirm.com",
"password": "password"
+1 -1
View File
@@ -22,7 +22,7 @@ document.addEventListener('DOMContentLoaded', function () {
const result = await response.json();
if (response.ok && result.success) {
// Set cookie with email and name
document.cookie = `id=${result.user.id};`;
document.cookie = `email=${result.user.email};`;
document.cookie = `name=${result.user.name};`;
+110 -1
View File
@@ -62,14 +62,122 @@ document.addEventListener('DOMContentLoaded', function() {
ceoInfoButton.addEventListener('click', () => {
console.log('Ceo Info Button pressed');
const domain = window.location.hostname;
const endpoint = 'http://' + domain + ':5000/admin/ceo';
const id = getCookie('id');
fetch(endpoint, {
method: 'GET',
headers: {
'Authorization': id
},
})
.then(async response => {
if (!response.ok) {
const responseData = await response.json();
throw new Error(responseData.message);
}
return await response.json()
})
.then(data => {
alert(data.message);
// Assuming 'data' is the property you want to download
const toDownload = data.data;
const jsonStr = JSON.stringify(toDownload, null, 2);
const blob = new Blob([jsonStr], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'ceo.json';
document.body.appendChild(a);
a.click();
// Cleanup: remove the link and revoke the URL
document.body.removeChild(a);
URL.revokeObjectURL(url);
})
.catch(error => {
alert(error)
console.error('Error: '+ error)
});
})
usersInfoButton.addEventListener('click', () => {
console.log('Users Info Button pressed');
const domain = window.location.hostname;
const endpoint = 'http://' + domain + ':5000/admin/users';
const id = getCookie('id');
fetch(endpoint, {
method: 'GET',
headers: {
'Authorization': id
},
})
.then(async response => {
if (!response.ok) {
const responseData = await response.json();
throw new Error(responseData.message);
}
return await response.json()
})
.then(data => {
alert(data.message);
const toDownload = data.data;
const jsonStr = JSON.stringify(toDownload, null, 2);
const blob = new Blob([jsonStr], { type: 'application/json' });
const url = URL.createObjectURL(blob);
// Create a temporary link to trigger the download
const a = document.createElement('a');
a.href = url;
a.download = 'users.json';
document.body.appendChild(a);
a.click();
// Cleanup: remove the link and revoke the URL
document.body.removeChild(a);
URL.revokeObjectURL(url);
})
.catch(error => {
alert(error)
console.error('Error: '+ error)
});
})
resetUcButton.addEventListener('click', () => {
console.log('Set Conf Button pressed');
console.log('Reset UC Button pressed');
const domain = window.location.hostname;
const endpoint = 'http://' + domain + ':5000/admin/reset_server';
const id = getCookie('id');
fetch(endpoint, {
method: 'GET',
headers: {
'Authorization': id
},
})
.then(async response => {
if (!response.ok) {
const responseData = await response.json();
throw new Error(responseData.message);
}
return await response.json()
})
.then(data => alert(data.message))
.catch(error => {
alert(error)
console.error('Error: '+ error)
});
})
logoutButton.addEventListener('click', () => {
@@ -81,6 +189,7 @@ document.addEventListener('DOMContentLoaded', function() {
deleteCookie('email');
deleteCookie('name');
deleteCookie('id');
fadeOut('/login');
});
+3 -2
View File
@@ -15,7 +15,7 @@ function validateLogin(req, res, next) {
const {error, value} = schemas.loginModelSchema.validate(req.body);
if (error) {
res.status(statusCodes.BAD_REQUEST).json({success: false, error: error.details});
res.status(statusCodes.BAD_REQUEST).json({error: error.details});
} else {
next();
}
@@ -29,12 +29,13 @@ router.post('/', validateLogin, (req, res) => {
success: true,
message: 'Login successful',
user: {
id: config.id,
name: config.name,
email: config.email
}
});
} else {
res.status(statusCodes.UNAUTHORIZED).json({ success: false, message: 'Invalid email or password' });
res.status(statusCodes.UNAUTHORIZED).json({message: 'Invalid email or password' });
}
});
module.exports = router;
-4
View File
@@ -43,8 +43,4 @@ router.post('/server', async (req, res) => {
}
});
router.post('ceo_credentials', (req, res) => {
});
module.exports = router;