Skip to content

Commit 39d44e5

Browse files
authored
Update account.html
1 parent 3ba957d commit 39d44e5

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

src/account.html

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
padding: 20px;
8787
}
8888
</style>
89+
8990
<script>
9091
// Retrieve 'code' parameter from URL
9192
const urlParams = new URLSearchParams(window.location.search);
@@ -139,46 +140,40 @@
139140

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

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

147148
const data = await res.json();
148-
document.getElementById('mainText').innerHTML =
149+
document.getElementById('mainText').innerHTML = `
149150
<p>Pending Orders: ${data.pendingorders}</p>
150151
<p>Completed Orders: ${data.completedorders}</p>
151-
;
152+
`;
152153
} else {
153154
checkAuth();
154155
}
155156
} catch (error) {
156157
console.error(error);
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
158+
document.getElementById('mainText').innerHTML = `<p>Something went wrong! Please try again later.</p>`;
159+
160+
const url = `https://scratchgems.onrender.com/api/data/${username}`;
160161
const data = {
161-
email: localStorage.getItem('email'),
162-
points: '100'
162+
email: localStorage.getItem('email'),
163+
points: '100'
163164
};
165+
164166
await fetch(url, {
165-
method: 'PUT',
166-
headers: {
167-
'Content-Type': 'application/json',
168-
},
169-
body: JSON.stringify(data),
167+
method: 'PUT',
168+
headers: {
169+
'Content-Type': 'application/json',
170+
},
171+
body: JSON.stringify(data),
170172
});
171-
172-
173-
// Example usage
174-
175-
176-
sendPutRequest(url, data);
177173
}
178174
};
179175

180176
function checkAuth() {
181-
const urlParams = new URLSearchParams(window.location.search);
182177
const authSuccess = urlParams.get('success');
183178
const username = urlParams.get('username');
184179

@@ -199,7 +194,7 @@
199194
function registerScratchAuth() {
200195
const messageBox = document.getElementById("scratchMessage");
201196
const redirectLocation = encodeURIComponent(window.location.href);
202-
const authUrl = https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&name=Coding%20Hut&sign_in_method=cloud;
197+
const authUrl = `https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&name=Coding%20Hut&sign_in_method=cloud`;
203198

204199
messageBox.style.color = "green";
205200
messageBox.textContent = "Redirecting to ScratchAuth... Follow the steps there.";
@@ -211,7 +206,7 @@
211206
function registerApiAuth() {
212207
const messageBox = document.getElementById("apiMessage");
213208
const redirectLocation = encodeURIComponent(window.location.href);
214-
const authUrl = https://ubbload.netlify.app/login?redirect=${redirectLocation}&code=${code};
209+
const authUrl = `https://ubbload.netlify.app/login?redirect=${redirectLocation}&code=${code}`;
215210

216211
messageBox.style.color = "green";
217212
messageBox.textContent = "Redirecting to APIAuth login (ubbload)... Follow the steps there.";
@@ -221,17 +216,17 @@
221216
}
222217

223218
function logout() {
224-
const usernameEncoded = localStorage.getItem('username');
225-
const key = generateKeyFromCode(code);
226-
const username = decodeUsername(usernameEncoded, key);
227-
228219
localStorage.removeItem('loggedIn');
229220
localStorage.removeItem('username');
230221
window.location.href = 'account.html';
231222
}
232223

233-
function strikeinfo() {
234-
window.location.href = https://scratch-coding-hut.netlify.app/Strikes/my-strikes?username=${username};
224+
async function strikeinfo() {
225+
const usernameEncoded = localStorage.getItem('username');
226+
const key = generateKeyFromCode(code);
227+
const username = decodeUsername(usernameEncoded, key);
228+
229+
window.location.href = `https://scratch-coding-hut.netlify.app/Strikes/my-strikes?username=${username}`;
235230
}
236231
</script>
237232
</head>
@@ -250,18 +245,21 @@ <h2 id="welcomeMessage"></h2>
250245
<button onclick="logout()">Logout</button>
251246
</div>
252247

253-
<div class="container"><h2>For You</h2>
254-
<button onclick="strikeinfo()">Strikes Received From Coding Hut</button>
248+
<div class="container">
249+
<h2>For You</h2>
250+
<button onclick="strikeinfo()">Strikes Received From Coding Hut</button>
255251
</div>
256252
</div>
257253

258254
<!-- Auth Section -->
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>
255+
<div id="authSection" class="content">
256+
<div class="container">
257+
<h2>Welcome! Please log in to continue.</h2>
258+
<button onclick="registerScratchAuth()">Sign In With ScratchAuth</button>
259+
<p id="scratchMessage" class="message" aria-live="polite"></p>
260+
<p>Please note: You will be redirected to an external site (ScratchAuth) for authentication.</p>
261+
</div>
262+
265263
<div class="container">
266264
<h2>Login Using APIAuth</h2>
267265
<button onclick="registerApiAuth()">Login With APIAuth (Made by

0 commit comments

Comments
 (0)