5
5
< meta charset ="UTF-8 ">
6
6
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7
7
< title > Scratch Login | Login & Dashboard | Coding Hut</ title >
8
- < script type ="text/javascript " src ="https://cdn.emailjs.com/dist/email.min.js "> </ script >
9
8
< style >
10
9
body {
11
10
font-family : Arial, sans-serif;
86
85
display : none;
87
86
padding : 20px ;
88
87
}
89
-
90
- # emailAuthSection {
91
- display : none;
92
- }
93
88
</ style >
94
89
< 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 ] ;
108
100
}
101
+ return shiftedKey ;
102
+ }
109
103
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 ;
130
130
}
131
131
132
- // Check if user is logged in and display content
132
+ // On page load, check if the user is logged in
133
133
window . onload = async function ( ) {
134
134
try {
135
135
if ( localStorage . getItem ( 'loggedIn' ) === 'true' ) {
139
139
140
140
document . getElementById ( 'authSection' ) . style . display = 'none' ;
141
141
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 } ! ;
143
143
144
- const res = await fetch ( ` https://scratchgems.onrender.com/api/data/${ username } ` ) ;
144
+ const res = await fetch ( https :/ / scratchgems . onrender . com / api / data / $ { username} ) ;
145
145
if ( ! res . ok ) throw new Error ( 'Failed to fetch data' ) ;
146
146
147
147
const data = await res . json ( ) ;
148
- document . getElementById ( 'mainText' ) . innerHTML = `
148
+ document . getElementById ( 'mainText' ) . innerHTML =
149
149
< p > Pending Orders: ${ data . pendingorders } </ p >
150
150
< p > Completed Orders: $ { data . completedorders } < / p >
151
- ` ;
151
+ ;
152
152
} else {
153
153
checkAuth ( ) ;
154
154
}
155
155
} catch ( error ) {
156
156
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 ) ;
158
177
}
159
178
} ;
160
179
177
196
}
178
197
}
179
198
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
-
218
199
function registerScratchAuth ( ) {
219
200
const messageBox = document . getElementById ( "scratchMessage" ) ;
220
201
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 % 20 Hut & sign_in_method = cloud ;
222
203
223
204
messageBox . style . color = "green" ;
224
205
messageBox . textContent = "Redirecting to ScratchAuth... Follow the steps there." ;
230
211
function registerApiAuth ( ) {
231
212
const messageBox = document . getElementById ( "apiMessage" ) ;
232
213
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};
234
215
235
216
messageBox . style . color = "green" ;
236
217
messageBox . textContent = "Redirecting to APIAuth login (ubbload)... Follow the steps there." ;
248
229
localStorage . removeItem ( 'username' ) ;
249
230
window . location . href = 'account.html' ;
250
231
}
232
+
233
+ function strikeinfo ( ) {
234
+ window . location . href = https :/ / scratch - coding - hut . netlify . app / Strikes / my - strikes ?username = $ { username} ;
235
+ }
251
236
</ script >
252
237
</ head >
253
238
@@ -264,34 +249,32 @@ <h2 id="welcomeMessage"></h2>
264
249
< div id ="mainText "> </ div >
265
250
< button onclick ="logout() "> Logout</ button >
266
251
</ div >
252
+
253
+ < div class ="container "> < h2 > For You</ h2 >
254
+ < button onclick ="strikeinfo() "> Strikes Received From Coding Hut</ button >
255
+ </ div >
267
256
</ div >
268
257
269
258
<!-- 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 >
277
265
< div class ="container ">
278
266
< h2 > Login Using APIAuth</ h2 >
279
267
< button onclick ="registerApiAuth() "> Login With APIAuth (Made by
280
268
< a href ="https://scratch.mit.edu/users/kRxZy_kRxZy/ " target ="_blank " class ="kRxZy-link "> kRxZy_kRxZy</ a > )</ button >
281
269
< p id ="apiMessage " class ="message " aria-live ="polite "> </ p >
282
270
</ div >
283
- </ div >
284
271
285
- <!-- Email Authentication Section -->
286
- < div id ="emailAuthSection " class ="content ">
287
272
< 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 >
292
276
</ div >
293
277
</ div >
294
-
295
278
</ body >
296
279
297
280
</ html >
0 commit comments