Skip to content

Commit 3ba957d

Browse files
authored
Update account.html
1 parent 62489e0 commit 3ba957d

File tree

1 file changed

+82
-99
lines changed

1 file changed

+82
-99
lines changed

src/account.html

Lines changed: 82 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Scratch Login | Login & Dashboard | Coding Hut</title>
8-
<script type="text/javascript" src="https://cdn.emailjs.com/dist/email.min.js"></script>
98
<style>
109
body {
1110
font-family: Arial, sans-serif;
@@ -86,50 +85,51 @@
8685
display: none;
8786
padding: 20px;
8887
}
89-
90-
#emailAuthSection {
91-
display: none;
92-
}
9388
</style>
9489
<script>
95-
// Initialize EmailJS with your User ID
96-
emailjs.init("zaCONCBcamstKQg3Y"); // Replace with your actual EmailJS User ID
97-
98-
// Function to send verification email
99-
function sendVerificationEmail() {
100-
const email = document.getElementById("userEmail").value;
101-
const messageBox = document.getElementById("emailMessage");
102-
103-
// Validate email input
104-
if (!email) {
105-
messageBox.style.color = "red";
106-
messageBox.textContent = "Please enter a valid email address.";
107-
return;
90+
// Retrieve 'code' parameter from URL
91+
const urlParams = new URLSearchParams(window.location.search);
92+
const code = urlParams.get('code') || '972'; // Default to '972' if no 'code' in URL
93+
94+
function generateKeyFromCode(code) {
95+
const baseKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
96+
let shiftedKey = '';
97+
let shift = parseInt(code) % 36; // Shift based on the code
98+
for (let i = 0; i < baseKey.length; i++) {
99+
shiftedKey += baseKey[(i + shift) % baseKey.length];
108100
}
101+
return shiftedKey;
102+
}
109103

110-
// Generate a unique verification code
111-
const verificationCode = Math.floor(100000 + Math.random() * 900000); // A 6-digit random code
112-
113-
const templateParams = {
114-
to_email: email,
115-
verification_code: verificationCode
116-
};
117-
118-
// Send email using EmailJS
119-
emailjs.send("service_uvr6x0c", "template_h7fc9a6", templateParams)
120-
.then(function(response) {
121-
console.log("Verification email sent successfully:", response);
122-
messageBox.style.color = "green";
123-
messageBox.textContent = `A verification code has been sent to ${email}. Please check your inbox.`;
124-
localStorage.setItem("verificationCode", verificationCode); // Store the code temporarily
125-
}, function(error) {
126-
console.log("Failed to send verification email:", error);
127-
messageBox.style.color = "red";
128-
messageBox.textContent = "Something went wrong. Please try again later.";
129-
});
104+
function encodeUsername(username, key) {
105+
const baseKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
106+
let encoded = '';
107+
for (let char of username) {
108+
let index = baseKey.indexOf(char);
109+
if (index !== -1) {
110+
encoded += key[index];
111+
} else {
112+
encoded += char;
113+
}
114+
}
115+
return encoded;
116+
}
117+
118+
function decodeUsername(encodedUsername, key) {
119+
const baseKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
120+
let decoded = '';
121+
for (let char of encodedUsername) {
122+
let index = key.indexOf(char);
123+
if (index !== -1) {
124+
decoded += baseKey[index];
125+
} else {
126+
decoded += char;
127+
}
128+
}
129+
return decoded;
130130
}
131131

132-
// Check if user is logged in and display content
132+
// On page load, check if the user is logged in
133133
window.onload = async function () {
134134
try {
135135
if (localStorage.getItem('loggedIn') === 'true') {
@@ -139,22 +139,41 @@
139139

140140
document.getElementById('authSection').style.display = 'none';
141141
document.getElementById('loggedInContent').style.display = 'block';
142-
document.getElementById('welcomeMessage').textContent = `Welcome to your account, ${username}!`;
142+
document.getElementById('welcomeMessage').textContent = Welcome to your account, ${username}!;
143143

144-
const res = await fetch(`https://scratchgems.onrender.com/api/data/${username}`);
144+
const res = await fetch(https://scratchgems.onrender.com/api/data/${username});
145145
if (!res.ok) throw new Error('Failed to fetch data');
146146

147147
const data = await res.json();
148-
document.getElementById('mainText').innerHTML = `
148+
document.getElementById('mainText').innerHTML =
149149
<p>Pending Orders: ${data.pendingorders}</p>
150150
<p>Completed Orders: ${data.completedorders}</p>
151-
`;
151+
;
152152
} else {
153153
checkAuth();
154154
}
155155
} catch (error) {
156156
console.error(error);
157-
document.getElementById('mainText').innerHTML = `<p>Something went wrong! Please try again later.</p>`;
157+
document.getElementById('mainText').innerHTML = <p>Something went wrong! Please try again later.</p>;
158+
// Function to send a PUT request to the API
159+
const url = https://scratchgems.onrender.com/api/data/${username}; // Replace with your API endpoint
160+
const data = {
161+
email: localStorage.getItem('email'),
162+
points: '100'
163+
};
164+
await fetch(url, {
165+
method: 'PUT',
166+
headers: {
167+
'Content-Type': 'application/json',
168+
},
169+
body: JSON.stringify(data),
170+
});
171+
172+
173+
// Example usage
174+
175+
176+
sendPutRequest(url, data);
158177
}
159178
};
160179

@@ -177,48 +196,10 @@
177196
}
178197
}
179198

180-
function generateKeyFromCode(code) {
181-
const baseKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
182-
let shiftedKey = '';
183-
let shift = parseInt(code) % 36; // Shift based on the code
184-
for (let i = 0; i < baseKey.length; i++) {
185-
shiftedKey += baseKey[(i + shift) % baseKey.length];
186-
}
187-
return shiftedKey;
188-
}
189-
190-
function encodeUsername(username, key) {
191-
const baseKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
192-
let encoded = '';
193-
for (let char of username) {
194-
let index = baseKey.indexOf(char);
195-
if (index !== -1) {
196-
encoded += key[index];
197-
} else {
198-
encoded += char;
199-
}
200-
}
201-
return encoded;
202-
}
203-
204-
function decodeUsername(encodedUsername, key) {
205-
const baseKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
206-
let decoded = '';
207-
for (let char of encodedUsername) {
208-
let index = key.indexOf(char);
209-
if (index !== -1) {
210-
decoded += baseKey[index];
211-
} else {
212-
decoded += char;
213-
}
214-
}
215-
return decoded;
216-
}
217-
218199
function registerScratchAuth() {
219200
const messageBox = document.getElementById("scratchMessage");
220201
const redirectLocation = encodeURIComponent(window.location.href);
221-
const authUrl = `https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&name=Coding%20Hut&sign_in_method=cloud`;
202+
const authUrl = https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&name=Coding%20Hut&sign_in_method=cloud;
222203

223204
messageBox.style.color = "green";
224205
messageBox.textContent = "Redirecting to ScratchAuth... Follow the steps there.";
@@ -230,7 +211,7 @@
230211
function registerApiAuth() {
231212
const messageBox = document.getElementById("apiMessage");
232213
const redirectLocation = encodeURIComponent(window.location.href);
233-
const authUrl = `https://ubbload.netlify.app/login?redirect=${redirectLocation}&code=${code}`;
214+
const authUrl = https://ubbload.netlify.app/login?redirect=${redirectLocation}&code=${code};
234215

235216
messageBox.style.color = "green";
236217
messageBox.textContent = "Redirecting to APIAuth login (ubbload)... Follow the steps there.";
@@ -248,6 +229,10 @@
248229
localStorage.removeItem('username');
249230
window.location.href = 'account.html';
250231
}
232+
233+
function strikeinfo() {
234+
window.location.href = https://scratch-coding-hut.netlify.app/Strikes/my-strikes?username=${username};
235+
}
251236
</script>
252237
</head>
253238

@@ -264,34 +249,32 @@ <h2 id="welcomeMessage"></h2>
264249
<div id="mainText"></div>
265250
<button onclick="logout()">Logout</button>
266251
</div>
252+
253+
<div class="container"><h2>For You</h2>
254+
<button onclick="strikeinfo()">Strikes Received From Coding Hut</button>
255+
</div>
267256
</div>
268257

269258
<!-- Auth Section -->
270-
<div id="authSection" class="content">
271-
<div class="container">
272-
<h2>Welcome! Please log in to continue.</h2>
273-
<button onclick="registerScratchAuth()">Sign In With ScratchAuth</button>
274-
<p id="scratchMessage" class="message" aria-live="polite"></p>
275-
<p>Please note: You will be redirected to an external site (ScratchAuth) for authentication.</p>
276-
</div>
259+
<div id="authSection" class="content"><div class="container">
260+
<h2>Welcome! Please log in to continue.</h2>
261+
<button onclick="registerScratchAuth()">Sign In With ScratchAuth</button>
262+
<p id="scratchMessage" class="message" aria-live="polite"></p>
263+
<p>Please note: You will be redirected to an external site (ScratchAuth) for authentication.</p>
264+
</div>
277265
<div class="container">
278266
<h2>Login Using APIAuth</h2>
279267
<button onclick="registerApiAuth()">Login With APIAuth (Made by
280268
<a href="https://scratch.mit.edu/users/kRxZy_kRxZy/" target="_blank" class="kRxZy-link">kRxZy_kRxZy</a>)</button>
281269
<p id="apiMessage" class="message" aria-live="polite"></p>
282270
</div>
283-
</div>
284271

285-
<!-- Email Authentication Section -->
286-
<div id="emailAuthSection" class="content">
287272
<div class="container">
288-
<h2>Please enter your email to receive a verification code:</h2>
289-
<input type="email" id="userEmail" placeholder="Enter your email address" required />
290-
<button onclick="sendVerificationEmail()">Send Verification Email</button>
291-
<p id="emailMessage" class="message" aria-live="polite"></p>
273+
<a href="https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/issues/new">
274+
<button>Having trouble signing in? Report an issue</button>
275+
</a>
292276
</div>
293277
</div>
294-
295278
</body>
296279

297280
</html>

0 commit comments

Comments
 (0)