diff --git a/index.js b/index.js index 151e115..c197a33 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,6 @@ var apiRouter = require('./routes/api'); var config = require("./config.json"); const watcher = chokidar.watch(config.DXMemorialImageDirectory, { - depth: 0, persistent: true }); diff --git a/readme.md b/readme.md index ac9bcd2..ccd1cd1 100644 --- a/readme.md +++ b/readme.md @@ -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: diff --git a/routes/api.js b/routes/api.js index dcda5d5..05b8346 100644 --- a/routes/api.js +++ b/routes/api.js @@ -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; \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 3356bee..2302ca0 100644 --- a/routes/index.js +++ b/routes/index.js @@ -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; \ No newline at end of file +module.exports = router; \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index 957ac0b..a02baff 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -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)); diff --git a/views/user.ejs b/views/user.ejs index 264dd09..5f009de 100644 --- a/views/user.ejs +++ b/views/user.ejs @@ -6,21 +6,57 @@