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 >
89 < style >
910 body {
1011 font-family : Arial, sans-serif;
8586 display : none;
8687 padding : 20px ;
8788 }
88- </ style >
89- < script >
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
9389
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 ] ;
100- }
101- return shiftedKey ;
90+ # emailAuthSection {
91+ display : none;
10292 }
103-
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- }
93+ </ style >
94+ < 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 ;
114108 }
115- return encoded ;
116- }
117109
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 ;
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+ } ) ;
130130 }
131131
132- // On page load, check if the user is logged in
132+ // Check if user is logged in and display content
133133 window . onload = async function ( ) {
134134 try {
135135 if ( localStorage . getItem ( 'loggedIn' ) === 'true' ) {
177177 }
178178 }
179179
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+
180218 function registerScratchAuth ( ) {
181219 const messageBox = document . getElementById ( "scratchMessage" ) ;
182220 const redirectLocation = encodeURIComponent ( window . location . href ) ;
210248 localStorage . removeItem ( 'username' ) ;
211249 window . location . href = 'account.html' ;
212250 }
213-
214- function strikeinfo ( ) {
215- window . location . href = 'https://scratch-coding-hut.netlify.app/Strikes/my-strikes?username=${username}' ;
216- }
217251 </ script >
218252</ head >
219253
@@ -230,32 +264,34 @@ <h2 id="welcomeMessage"></h2>
230264 < div id ="mainText "> </ div >
231265 < button onclick ="logout() "> Logout</ button >
232266 </ div >
233-
234- < div class ="container "> < h2 > For You</ h2 >
235- < button onclick ="strikeinfo() "> Strikes Received From Coding Hut</ button >
236- </ div >
237267 </ div >
238268
239269 <!-- Auth Section -->
240- < div id ="authSection " class ="content "> < div class ="container ">
241- < h2 > Welcome! Please log in to continue.</ h2 >
242- < button onclick ="registerScratchAuth() "> Sign In With ScratchAuth</ button >
243- < p id ="scratchMessage " class ="message " aria-live ="polite "> </ p >
244- < p > Please note: You will be redirected to an external site (ScratchAuth) for authentication.</ p >
245- </ div >
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 >
246277 < div class ="container ">
247278 < h2 > Login Using APIAuth</ h2 >
248279 < button onclick ="registerApiAuth() "> Login With APIAuth (Made by
249280 < a href ="https://scratch.mit.edu/users/kRxZy_kRxZy/ " target ="_blank " class ="kRxZy-link "> kRxZy_kRxZy</ a > )</ button >
250281 < p id ="apiMessage " class ="message " aria-live ="polite "> </ p >
251282 </ div >
283+ </ div >
252284
285+ <!-- Email Authentication Section -->
286+ < div id ="emailAuthSection " class ="content ">
253287 < div class ="container ">
254- < a href ="https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/issues/new ">
255- < button > Having trouble signing in? Report an issue</ button >
256- </ a >
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 >
257292 </ div >
258293 </ div >
294+
259295</ body >
260296
261297</ html >
0 commit comments