2
2
< html lang ="en ">
3
3
4
4
< 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 " / >
7
7
< title > Scratch Login | Login & Dashboard | Coding Hut</ title >
8
8
< style >
9
9
body {
31
31
box-shadow : 0 2px 10px rgba (0 , 0 , 0 , 0.1 );
32
32
}
33
33
34
- .message {
35
- color : red;
36
- font-weight : bold;
37
- margin-top : 10px ;
38
- }
39
-
34
+ .message ,
40
35
.devTokens {
41
36
color : red;
42
37
font-weight : bold;
79
74
}
80
75
81
76
a .kRxZy-link {
82
- color : # 4CAF50 ;
77
+ color : # 4caf50 ;
83
78
font-weight : bold;
84
79
}
85
80
86
81
a .kRxZy-link : hover {
87
- color : # 388E3C ;
82
+ color : # 388e3c ;
88
83
}
89
84
90
85
# loggedInContent {
94
89
</ style >
95
90
96
91
< script >
97
- // Function to decode the username using atob (Base64 decoding)
98
92
function decodeUsername ( encodedUsername ) {
99
- return atob ( encodedUsername ) ; // Using atob to decode the Base64 username
93
+ return atob ( encodedUsername ) ;
100
94
}
101
95
102
- // Function to encode the username using btoa() (Base64 encoding)
103
96
function encodeUsername ( username ) {
104
- return btoa ( username ) ; // Using btoa to encode the username to Base64
97
+ return btoa ( username ) ;
105
98
}
106
99
107
- // On page load, check if the user is logged in
108
100
window . onload = async function ( ) {
109
101
try {
110
102
if ( localStorage . getItem ( 'loggedIn' ) === 'true' ) {
111
103
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 ) ;
114
106
115
107
document . getElementById ( 'authSection' ) . style . display = 'none' ;
116
108
document . getElementById ( 'loggedInContent' ) . style . display = 'block' ;
125
117
<p>Completed Orders: ${ data . completedorders } </p>
126
118
` ;
127
119
} else {
128
- checkAuth ( ) ;
120
+ await checkAuth ( ) ;
129
121
}
130
122
} catch ( error ) {
131
123
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>` ;
133
125
}
134
126
} ;
135
127
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' ) ;
138
130
139
131
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 ) ;
156
151
}
157
-
158
- }
159
-
160
- if ( authSuccess === 'true' ) {
161
- localStorage . setItem ( 'loggedIn' , 'true' ) ;
162
- window . location . href = 'index.html' ;
163
152
}
164
153
}
165
154
190
179
function logout ( ) {
191
180
localStorage . removeItem ( 'loggedIn' ) ;
192
181
localStorage . removeItem ( 'username' ) ;
182
+ localStorage . removeItem ( 'usernameEnc' ) ;
193
183
window . location . href = 'account.html' ;
194
184
}
195
185
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
+ }
198
191
}
199
192
200
193
function devToken ( ) {
201
194
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
+ }
206
202
}
207
203
</ script >
208
204
</ head >
@@ -225,15 +221,15 @@ <h2 id="welcomeMessage"></h2>
225
221
< h2 > For You</ h2 >
226
222
< button onclick ="strikeinfo() "> Strikes Received From Coding Hut</ button >
227
223
</ div >
228
- <!-- DO NOT DELETE MY AUTH TOKEN SYSTEM -->
224
+
225
+ <!-- Developer Token -->
229
226
< div class ="container ">
230
227
< h2 > Developer Tokens</ h2 >
231
228
< h3 > Used for linking Scratch account to forums account</ h3 >
232
229
< p id ="devTokens " class ="message " aria-live ="polite "> </ p >
233
230
< button onclick ="devToken() "> Generate Dev Token</ button >
234
231
Coming Soon! Stay tuned
235
232
</ div >
236
- <!-- DO NOT DELETE MY AUTH TOKEN SYSTEM -->
237
233
</ div >
238
234
239
235
<!-- Auth Section -->
0 commit comments