22< html lang ="en ">
33
44< head >
5- < meta charset ="UTF-8 ">
6- < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
5+ < meta charset ="UTF-8 " / >
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " / >
77 < title > Scratch Login | Login & Dashboard | Coding Hut</ title >
88 < style >
99 body {
3131 box-shadow : 0 2px 10px rgba (0 , 0 , 0 , 0.1 );
3232 }
3333
34- .message {
35- color : red;
36- font-weight : bold;
37- margin-top : 10px ;
38- }
39-
34+ .message ,
4035 .devTokens {
4136 color : red;
4237 font-weight : bold;
7974 }
8075
8176 a .kRxZy-link {
82- color : # 4CAF50 ;
77+ color : # 4caf50 ;
8378 font-weight : bold;
8479 }
8580
8681 a .kRxZy-link : hover {
87- color : # 388E3C ;
82+ color : # 388e3c ;
8883 }
8984
9085 # loggedInContent {
9489 </ style >
9590
9691 < script >
97- // Function to decode the username using atob (Base64 decoding)
9892 function decodeUsername ( encodedUsername ) {
99- return atob ( encodedUsername ) ; // Using atob to decode the Base64 username
93+ return atob ( encodedUsername ) ;
10094 }
10195
102- // Function to encode the username using btoa() (Base64 encoding)
10396 function encodeUsername ( username ) {
104- return btoa ( username ) ; // Using btoa to encode the username to Base64
97+ return btoa ( username ) ;
10598 }
10699
107- // On page load, check if the user is logged in
108100 window . onload = async function ( ) {
109101 try {
110102 if ( localStorage . getItem ( 'loggedIn' ) === 'true' ) {
111103 const usernameEncoded = localStorage . getItem ( 'usernameEnc' ) ;
112- const username = decodeUsername ( usernameEncoded ) ; // Decode the username using atob
113- localStorage . setItem ( 'username' , username )
104+ const username = decodeUsername ( usernameEncoded ) ;
105+ localStorage . setItem ( 'username' , username ) ;
114106
115107 document . getElementById ( 'authSection' ) . style . display = 'none' ;
116108 document . getElementById ( 'loggedInContent' ) . style . display = 'block' ;
125117 <p>Completed Orders: ${ data . completedorders } </p>
126118 ` ;
127119 } else {
128- checkAuth ( ) ;
120+ await checkAuth ( ) ;
129121 }
130122 } catch ( error ) {
131123 console . error ( error ) ;
132- document . getElementById ( 'mainText' ) . innerHTML = `<p>Something went wrong! Please try again later.</p>` ;
124+ document . getElementById ( 'mainText' ) . innerHTML = `<p>Something went wrong! Please try again later.</p>` ;
133125 }
134126 } ;
135127
136- function checkAuth ( ) {
137- const PC = new URLSearchParams ( window . location . search ) . get ( 'privateCode' ) ;
128+ async function checkAuth ( ) {
129+ const PC = new URLSearchParams ( window . location . search ) . get ( 'privateCode' ) ;
138130
139131 if ( PC ) {
140- const res = await fetch ( `https://auth-api.itinerary.eu.org/auth/verifyToken/${ PC } ` ; // Decode the username using atob
141- const data = await res . json ( ) ;
142- const username = atob ( data . username ) ;
143- localStorage . setItem ( 'usernameEnc' , username ) ; // Store the original Base64-encoded username
144- localStorage . setItem ( 'username' , data . username ) ;
145- localStorage . setItem ( 'loggedIn' , 'true' ) ;
146- window . location . href = 'index.html' ;
147-
148- // Check if the user is on the first line of the Ban List
149- // Banned Users: No People Have Been Banned Yet!
150- if ( username === 'PUT THE FIRST BANNED USER HERE' ) {
151- // Code here is run if the user gets banned
152-
153- localStorage . removeItem ( 'loggedIn' ) ;
154- localStorage . removeItem ( 'username' ) ;
155- window . location . href = 'banscreen.html?reason=spam' ;
132+ try {
133+ const res = await fetch ( `https://auth-api.itinerary.eu.org/auth/verifyToken/${ PC } ` ) ;
134+ const data = await res . json ( ) ;
135+ const username = atob ( data . username ) ;
136+
137+ // Ban check (example logic)
138+ if ( username === 'PUT THE FIRST BANNED USER HERE' ) {
139+ localStorage . removeItem ( 'loggedIn' ) ;
140+ localStorage . removeItem ( 'username' ) ;
141+ window . location . href = 'banscreen.html?reason=spam' ;
142+ return ;
143+ }
144+
145+ localStorage . setItem ( 'usernameEnc' , data . username ) ; // base64
146+ localStorage . setItem ( 'username' , username ) ; // plain text
147+ localStorage . setItem ( 'loggedIn' , 'true' ) ;
148+ window . location . href = 'index.html' ;
149+ } catch ( err ) {
150+ console . error ( 'Token verification failed:' , err ) ;
156151 }
157-
158- }
159-
160- if ( authSuccess === 'true' ) {
161- localStorage . setItem ( 'loggedIn' , 'true' ) ;
162- window . location . href = 'index.html' ;
163152 }
164153 }
165154
190179 function logout ( ) {
191180 localStorage . removeItem ( 'loggedIn' ) ;
192181 localStorage . removeItem ( 'username' ) ;
182+ localStorage . removeItem ( 'usernameEnc' ) ;
193183 window . location . href = 'account.html' ;
194184 }
195185
196- async function strikeinfo ( ) {
197- window . location . href = `https://scratch-coding-hut.github.io/Strikes/my-strikes?username=${ username } ` ;
186+ function strikeinfo ( ) {
187+ const username = localStorage . getItem ( 'username' ) ;
188+ if ( username ) {
189+ window . location . href = `https://scratch-coding-hut.github.io/Strikes/my-strikes?username=${ username } ` ;
190+ }
198191 }
199192
200193 function devToken ( ) {
201194 const usernameEnc = localStorage . getItem ( 'usernameEnc' ) ;
202- const username = localStorage . getItem ( 'username' ) ;
203- const joined = "Your dev token is: " + usernameEnc + " - Make sure to only share it with Coding Hut services and partners or else you can get hacked!" ;
204- devTokens . style . color = "green" ;
205- devTokens . textContent = joined ;
195+ const devTokens = document . getElementById ( 'devTokens' ) ;
196+
197+ if ( usernameEnc && devTokens ) {
198+ const joined = "Your dev token is: " + usernameEnc + " - Make sure to only share it with Coding Hut services and partners or else you can get hacked!" ;
199+ devTokens . style . color = "green" ;
200+ devTokens . textContent = joined ;
201+ }
206202 }
207203 </ script >
208204</ head >
@@ -225,15 +221,15 @@ <h2 id="welcomeMessage"></h2>
225221 < h2 > For You</ h2 >
226222 < button onclick ="strikeinfo() "> Strikes Received From Coding Hut</ button >
227223 </ div >
228- <!-- DO NOT DELETE MY AUTH TOKEN SYSTEM -->
224+
225+ <!-- Developer Token -->
229226 < div class ="container ">
230227 < h2 > Developer Tokens</ h2 >
231228 < h3 > Used for linking Scratch account to forums account</ h3 >
232229 < p id ="devTokens " class ="message " aria-live ="polite "> </ p >
233230 < button onclick ="devToken() "> Generate Dev Token</ button >
234231 Coming Soon! Stay tuned
235232 </ div >
236- <!-- DO NOT DELETE MY AUTH TOKEN SYSTEM -->
237233 </ div >
238234
239235 <!-- Auth Section -->
0 commit comments