diff --git a/public/javascript/login.js b/public/javascript/login.js new file mode 100644 index 0000000..aa4dcad --- /dev/null +++ b/public/javascript/login.js @@ -0,0 +1,71 @@ + + // Get the cookie string + const cookieString = document.cookie; + + // Parse the cookie string and extract the values + const cookies = cookieString.split(';'); + let ext_id, luid; + + for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + const cookieParts = cookie.split('='); + + if (cookieParts[0] === 'ext_id') { + ext_id = cookieParts[1]; + } + + if (cookieParts[0] === 'luid') { + luid = cookieParts[1]; + } + } + + // Sends user to User Page if already signed in + if (ext_id && luid) { + console.log(`User Data Detected, sending to user page.`); + window.location = "/user"; + } else { + console.log('User Data Not Detected! Please Sign In.'); + } + + + const form = document.getElementById("myForm"); + form.addEventListener("submit", function(event) { + event.preventDefault(); // Prevent the default form submission behavior + + const input = document.getElementsByName("myInput")[0].value; + const url = "/api/getExtId"; // Replace with your API endpoint URL + + // Send the input data to the API endpoint using fetch + fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + input: input + }) + }) + .then(response => response.json()) + .then(data => { + console.log(data) + let releventData = { + luid: data.data.luid, + ext_id: data.data.ext_id + } + console.log(releventData) + // 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)); + }); \ No newline at end of file diff --git a/public/javascript/user.js b/public/javascript/user.js new file mode 100644 index 0000000..e1b7998 --- /dev/null +++ b/public/javascript/user.js @@ -0,0 +1,105 @@ +// Get the clear storage button element +const clearStorageBtn = document.getElementById('clear-storage-btn'); + +// Add a click event listener to the clear storage button +clearStorageBtn.addEventListener('click', () => { + // 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_id, luid; + +for (let i = 0; i < cookies.length; i++) { + const cookie = cookies[i].trim(); + const cookieParts = cookie.split('='); + + if (cookieParts[0] === 'ext_id') { + ext_id = cookieParts[1]; + } + + if (cookieParts[0] === 'luid') { + luid = cookieParts[1]; + } +} + +// Send the user to the sign in page if they aren't already signed in to the website. +if (ext_id && luid) { + console.log(`ext_id: ${ext_id}, luid: ${luid}`); + +} else { + console.log('User Data Not Detected! Please Sign In.'); + window.location = "/"; +} +const userdata = JSON.parse(document.currentScript.getAttribute('data-userdata')); + +// Check if the user image element exists +if(userdata.icon_id === 10) { + const userImage = document.getElementById('user-image'); + userImage.src = "images/" + ext_id + '-up.jpg'; +} else if (document.currentScript.getAttribute('data-userdata')) { + const userImage = document.getElementById('user-image'); + const UI_Icon = userdata.icon_id; + + // Pad the number because game weird + function padNumber(num, size) { + let s = num + ""; + while (s.length < size) { + s = "0" + s; + } + return s; + } + + // Set the user image source + userImage.src = "assets/icon/UI_Icon_" + padNumber(Number(UI_Icon), 6) + '.png'; +} + +// title getting +const request = new XMLHttpRequest(); +request.open('GET', '/assets/metadata/titleMetadata.json', true); + +request.onload = function() { + if (this.status >= 200 && this.status < 400) { + const data = JSON.parse(this.response); + const userTitle = document.getElementById('user-title-text'); + var userTitleText = "" + for (title of data) { + if(userdata.title_id === title.titleId) { + userTitleText = title.name + break + } + continue + } + userTitle.textContent = userTitleText + } else { + // handle the error + } +}; + +request.onerror = function() { + // handle the error +}; + +request.send(); diff --git a/public/stylesheets/user.css b/public/stylesheets/user.css index 3f42121..6a74026 100644 --- a/public/stylesheets/user.css +++ b/public/stylesheets/user.css @@ -2,8 +2,8 @@ display: block; margin-left: auto; margin-right: auto; - max-width: 8em; - height: auto; + max-width: 100%; + width: 100%; } #User { @@ -11,4 +11,80 @@ margin-left: auto; margin-right: auto; margin: 1%; +} + +#wrapper { + display: flex; + justify-content: center; + align-items: center; +} + +#user-profile-wrapper { + display: inline-grid; + margin: 0px; + grid-template-areas: + "profile-image user-title user-title" + "profile-image user-name dx-rating" + "profile-image user-class awakens"; + gap: 10px; + border: 2px solid black; + border-radius: 10px; + justify-items: center; + align-items: center; + width: fit-content; + margin: 0 auto; +} + +@media screen and (max-width: 768px) { + #user-profile-wrapper { + display: inline-block; + margin: 0; + padding: 20px; + border: 2px solid black; + border-radius: 10px; + align-items: center; + justify-content: center; + } +} + +.profile-image { + grid-area: profile-image; + max-width: 100%; + width: 100%; +} + +.user-title { + grid-area: user-title; +} + +.user-name { + grid-area: user-name; +} + +.dx-rating { + grid-area: dx-rating; +} + +.user-rank { + grid-area: user-rank; +} + +.awakens { + grid-area: awakens; +} + +h4 { + font-size: 2em; +} + +@media (max-width: 768px) { + h4 { + font-size: 1.5em; + } +} + +@media (max-width: 480px) { + h4 { + font-size: 1.2em; + } } \ No newline at end of file diff --git a/readme.md b/readme.md index 0310448..97c02cb 100644 --- a/readme.md +++ b/readme.md @@ -36,13 +36,15 @@ Create a `config.json` file and paste this in, with paths to your instance. # Project Progress ToDo: -- Make User Profile on User Page (almost done) - - fuck you go work on divs and grids and spacing and go watch Hyperplexed you no name piece of shit - literally me talking to me - -- Literally everything else +- Create Play Data Tab +- Create Photos Tab +- Create Area Tab +- Create Collection Tab +- Create Ranking Tab +- Create Options Tab +- add a background i guess Complete: - Sign In Page - Make User Profile on User Page (almost done) - - (Done) Get User Data, and send it. - - (Done) Grab the User Profile, and get the custom one if the user icon ID is set to 10. \ No newline at end of file + - Fuck you css go kill yourself \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index 3c3f46c..2eb63dc 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -1,85 +1,16 @@ <% var rootPath='../' ; %> - <%- include(rootPath + 'templates/header.ejs' ); %> +<%- include(rootPath + 'templates/header.ejs' ); %> -