86
86
padding : 20px ;
87
87
}
88
88
</ style >
89
+
89
90
< script >
90
91
// Retrieve 'code' parameter from URL
91
92
const urlParams = new URLSearchParams ( window . location . search ) ;
139
140
140
141
document . getElementById ( 'authSection' ) . style . display = 'none' ;
141
142
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 } !` ;
143
144
144
- const res = await fetch ( https :/ / scratchgems . onrender . com / api / data / $ { username} ) ;
145
+ const res = await fetch ( ` https://scratchgems.onrender.com/api/data/${ username } ` ) ;
145
146
if ( ! res . ok ) throw new Error ( 'Failed to fetch data' ) ;
146
147
147
148
const data = await res . json ( ) ;
148
- document . getElementById ( 'mainText' ) . innerHTML =
149
+ document . getElementById ( 'mainText' ) . innerHTML = `
149
150
<p>Pending Orders: ${ data . pendingorders } </p>
150
151
<p>Completed Orders: ${ data . completedorders } </p>
151
- ;
152
+ ` ;
152
153
} else {
153
154
checkAuth ( ) ;
154
155
}
155
156
} catch ( error ) {
156
157
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 } ` ;
160
161
const data = {
161
- email : localStorage . getItem ( 'email' ) ,
162
- points : '100'
162
+ email : localStorage . getItem ( 'email' ) ,
163
+ points : '100'
163
164
} ;
165
+
164
166
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 ) ,
170
172
} ) ;
171
-
172
-
173
- // Example usage
174
-
175
-
176
- sendPutRequest ( url , data ) ;
177
173
}
178
174
} ;
179
175
180
176
function checkAuth ( ) {
181
- const urlParams = new URLSearchParams ( window . location . search ) ;
182
177
const authSuccess = urlParams . get ( 'success' ) ;
183
178
const username = urlParams . get ( 'username' ) ;
184
179
199
194
function registerScratchAuth ( ) {
200
195
const messageBox = document . getElementById ( "scratchMessage" ) ;
201
196
const redirectLocation = encodeURIComponent ( window . location . href ) ;
202
- const authUrl = https :/ / auth . itinerary . eu . org / auth /?redirect = $ { redirectLocation} & name = Coding % 20 Hut & sign_in_method = cloud ;
197
+ const authUrl = ` https://auth.itinerary.eu.org/auth/?redirect=${ redirectLocation } &name=Coding%20Hut&sign_in_method=cloud` ;
203
198
204
199
messageBox . style . color = "green" ;
205
200
messageBox . textContent = "Redirecting to ScratchAuth... Follow the steps there." ;
211
206
function registerApiAuth ( ) {
212
207
const messageBox = document . getElementById ( "apiMessage" ) ;
213
208
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 } ` ;
215
210
216
211
messageBox . style . color = "green" ;
217
212
messageBox . textContent = "Redirecting to APIAuth login (ubbload)... Follow the steps there." ;
221
216
}
222
217
223
218
function logout ( ) {
224
- const usernameEncoded = localStorage . getItem ( 'username' ) ;
225
- const key = generateKeyFromCode ( code ) ;
226
- const username = decodeUsername ( usernameEncoded , key ) ;
227
-
228
219
localStorage . removeItem ( 'loggedIn' ) ;
229
220
localStorage . removeItem ( 'username' ) ;
230
221
window . location . href = 'account.html' ;
231
222
}
232
223
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 } ` ;
235
230
}
236
231
</ script >
237
232
</ head >
@@ -250,18 +245,21 @@ <h2 id="welcomeMessage"></h2>
250
245
< button onclick ="logout() "> Logout</ button >
251
246
</ div >
252
247
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 >
255
251
</ div >
256
252
</ div >
257
253
258
254
<!-- 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
+
265
263
< div class ="container ">
266
264
< h2 > Login Using APIAuth</ h2 >
267
265
< button onclick ="registerApiAuth() "> Login With APIAuth (Made by
0 commit comments