1
0
mirror of https://dev.s-ul.net/Galexion/MaiMaiDXNet.git synced 2024-11-27 23:10:50 +01:00

added user finding and undepthed the watcher so user images can be detected.

This commit is contained in:
Galexion 2023-02-16 21:49:08 -05:00
parent 32ca13816c
commit f280aec60f
6 changed files with 121 additions and 32 deletions

View File

@ -10,7 +10,6 @@ var apiRouter = require('./routes/api');
var config = require("./config.json");
const watcher = chokidar.watch(config.DXMemorialImageDirectory, {
depth: 0,
persistent: true
});

View File

@ -25,6 +25,8 @@ Then, create the `/public/image/` folder. this will be where the images will be
ToDo:
- Make User Profile on User Page
- (Done) Get User Data, and send it.
- Grab the User Profile, and get the custom one if the user icon ID is set to 10.
- Literally everything else
Complete:

View File

@ -28,7 +28,27 @@ let db = new sqlite3.Database('A:\\db.sqlite');
});
router.post('/getUserData/', function (req,res,next) {
db.all('SELECT * FROM maimai2_user_detail', (err, rows) => {
if (err) {
console.error(err);
// Return a Failed Message.
res.status(500).json({ error: err.message, status: "Failed" });
} else {
// Make the Request easier to get to.
var request = req.body;
var mUser = undefined // Leave the Matched User undefined until the user is found.
for (user of rows) { // For Each User in Rows
if (request.input === user.aime_card_id) { // If the Access Code for the card is in the system,
mUser = user; // set the Matched User Variable to the User, and break the for Loop.
break
}
}
// Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile.
res.status(200).json({ data: mUser, status: "Complete" });
}
});
})
module.exports = router;

View File

@ -10,33 +10,57 @@ router.get('/', function (req, res, next) {
db.all('SELECT * FROM sega_card', (err, rows) => {
if (err) {
console.error(err);
res.render('error', {error: err});
res.render('error', { error: err });
} else {
console.log(rows);
console.log(`There are Currently ${rows.length} Users Registered.`); // this check could probably be changed into an API
var params = {
totalUsers: rows.length
}
res.render('index', {title: title, params: params});
res.render('index', { title: title, params: params });
}
});
});
});
router.get('/user', function (req, res, next) {
db.all('SELECT * FROM sega_card', (err, rows) => {
router.get('/user', async function (req, res, next) {
try{
const cookies = req.cookies
console.log(cookies)
if (cookies.aime_card_id === undefined) {
return res.render('index', { title: title });
}
res.render('user', { title: title, userdata: await getUserData(req) });
} catch (err) {
res.render('error', { error: err });
}
});
async function getUserData(req) {
return new Promise((resolve, reject) => {
const cookies = req.cookies
db.all('SELECT * FROM maimai2_user_detail', (err, rows) => {
if (err) {
console.error(err);
res.render('error', {error: err});
// Return a Failed Message.
reject(err)
} else {
console.log(rows);
console.log(`There are Currently ${rows.length} Users Registered.`); // this check could probably be changed into an API
var params = {
totalUsers: rows.length
// Make the Request easier to get to.
var mUser = undefined // Leave the Matched User undefined until the user is found.
for (user of rows) { // For Each User in Rows
if (cookies.aime_card_id === user.aime_card_id.toString()) { // If the Access Code for the card is in the system,
mUser = user; // set the Matched User Variable to the User, and break the for Loop.
break;
}
}
if (mUser) {
// Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile.
resolve(mUser);
} else {
reject(new Error('User not found'));
}
res.render('user', {title: title, params: params});
}
});
});
} // function is required to obtain the User Data, and create the user profile. I'm going to bed.
module.exports = router;
module.exports = router;

View File

@ -46,10 +46,18 @@
console.log(data)
let releventData = { luid: data.data.luid, ext_id: data.data.ext_id }
console.log(releventData)
// Save data to local storage
localStorage.setItem('ext_id', data.data.ext_id);
localStorage.setItem('luid', data.data.luid);
localStorage.setItem('aimeid', data.data.id);
// Set the cookie expiration to 7 days from now
const expirationDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
// Set the ext_id cookie
document.cookie = `ext_id=${data.data.ext_id}; expires=${expirationDate.toUTCString()}`;
// Set the luid cookie
document.cookie = `luid=${data.data.luid}; expires=${expirationDate.toUTCString()}`;
console.log(data.data.id)
// Set the aime_card_id cookie
document.cookie = `aime_card_id=${data.data.id.toString()}; expires=${expirationDate.toUTCString()}`;
// Set the cookie
window.location = "/user";
})
.catch(error => console.error(error));

View File

@ -6,21 +6,57 @@
<script>
const extId = localStorage.getItem('ext_id');
const luid = localStorage.getItem('luid');
if (extId === null || luid === null) {
console.log('User Data Not Detected! Please Sign In.');
window.location = "/";
} else {
console.log(`User Data Found!`);
}
const clearStorageBtn = document.getElementById('clear-storage-btn');
clearStorageBtn.addEventListener('click', () => {
localStorage.removeItem('ext_id');
localStorage.removeItem('luid');
localStorage.removeItem('aimeid');
// Remove the cookies
function removeCookies() {
// Set the expiration date to a date in the past
const expirationDate = new Date(0).toUTCString();
// Set the ext_id cookie to expire
document.cookie = `ext_id=; expires=${expirationDate}`;
// Set the luid cookie to expire
document.cookie = `luid=; expires=${expirationDate}`;
// Set the aime_card_id cookie to expire
document.cookie = `aime_card_id=; expires=${expirationDate}`;
}
// Example usage
removeCookies();
console.log('Local storage cleared.');
window.location = "/";
});
// Get the cookie string
const cookieString = document.cookie;
// Parse the cookie string and extract the values
const cookies = cookieString.split(';');
let ext_id2, luid2;
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
const cookieParts = cookie.split('=');
if (cookieParts[0] === 'ext_id') {
ext_id2 = cookieParts[1];
}
if (cookieParts[0] === 'luid') {
luid2 = cookieParts[1];
}
}
// Use the values as needed
if (ext_id2 && luid2) {
console.log(`ext_id: ${ext_id2}, luid: ${luid2}`);
} else {
console.log('User Data Not Detected! Please Sign In.');
window.location = "/";
}
</script>
<details>