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

fixed bug where index.ejs wouldnt send people to /user if they were already signed in, documented stuff

This commit is contained in:
Galexion 2023-02-17 01:33:10 -05:00
parent a8d06a4ae1
commit 3a16706814
2 changed files with 29 additions and 11 deletions

View File

@ -1,6 +1,6 @@
<% var rootPath='../' ; %> <% var rootPath='../' ; %>
<%- include(rootPath + 'templates/header.ejs' ); %> <%- include(rootPath + 'templates/header.ejs' ); %>
<div id="loginContent"> <div id="loginContent">
<h1>MaiMaiDX.Net</h1> <h1>MaiMaiDX.Net</h1>
<h5>Total Users Registered: <%= params.totalUsers %> <h5>Total Users Registered: <%= params.totalUsers %>
@ -13,14 +13,32 @@
</form> </form>
<script> <script>
const extId = localStorage.getItem('ext_id'); // Get the cookie string
const luid = localStorage.getItem('luid'); const cookieString = document.cookie;
if (extId === null || luid === null) { // Parse the cookie string and extract the values
console.log('User Data Not Detected! Please Sign In.'); const cookies = cookieString.split(';');
} else { let ext_id2, luid2;
console.log(`User Data Found! Redirecting to User Page.`);
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];
}
}
// Sends user to User Page if already signed in
if (ext_id2 && luid2) {
console.log(`User Data Detected, sending to user page.`);
window.location = "/user"; window.location = "/user";
} else {
console.log('User Data Not Detected! Please Sign In.');
} }

View File

@ -54,7 +54,7 @@
} }
} }
// Use the values as needed // Sends user to the sign in page if they aren't already signed in to the website.
if (ext_id2 && luid2) { if (ext_id2 && luid2) {
console.log(`ext_id: ${ext_id2}, luid: ${luid2}`); console.log(`ext_id: ${ext_id2}, luid: ${luid2}`);
@ -64,7 +64,7 @@
} }
</script> </script>
<% if(userdata.icon_id===10) { %> <% if(userdata.icon_id===10) { %> <!-- If the user icon id is set to 10, it's a custom image and you need to grab the image that the user uploaded. -->
<img id="user-image" src="" alt="User Image"> <img id="user-image" src="" alt="User Image">
<script> <script>
@ -72,14 +72,14 @@
userImage.src = "images/" + ext_id2 + '-up.jpg'; userImage.src = "images/" + ext_id2 + '-up.jpg';
</script> </script>
<% } else {%> <% } else {%> <!-- If Not, use the userdata.icon_id variable to find which icon you need. -->
<img id="user-image" src="" alt="User Image"> <img id="user-image" src="" alt="User Image">
<script data-userdata="<%=JSON.stringify(userdata)%>"> <script data-userdata="<%=JSON.stringify(userdata)%>">
const userdata = JSON.parse(document.currentScript.getAttribute('data-userdata')); const userdata = JSON.parse(document.currentScript.getAttribute('data-userdata'));
const userImage = document.getElementById('user-image'); const userImage = document.getElementById('user-image');
const UI_Icon = userdata.icon_id const UI_Icon = userdata.icon_id
function padNumber(num, size) { function padNumber(num, size) { // pad the number because haha game weird
var s = num + ""; var s = num + "";
while (s.length < size) s = "0" + s; while (s.length < size) s = "0" + s;
return s; return s;