|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html lang="en"> |
| 3 | + |
3 | 4 | <head> |
4 | 5 | <meta charset="UTF-8"> |
5 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
12 | 13 | background-color: #f4f4f4; |
13 | 14 | text-align: center; |
14 | 15 | } |
| 16 | + |
15 | 17 | .header { |
16 | 18 | background-color: #c04d4d; |
17 | 19 | color: white; |
18 | 20 | padding: 20px; |
19 | 21 | box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); |
20 | 22 | } |
21 | | - .content, .container { |
| 23 | + |
| 24 | + .content, |
| 25 | + .container { |
22 | 26 | padding: 20px; |
23 | 27 | max-width: 600px; |
24 | 28 | margin: 20px auto; |
25 | 29 | background-color: white; |
26 | 30 | border-radius: 8px; |
27 | 31 | box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); |
28 | 32 | } |
| 33 | + |
29 | 34 | .message { |
30 | 35 | color: red; |
31 | 36 | font-weight: bold; |
32 | 37 | margin-top: 10px; |
33 | 38 | } |
| 39 | + |
34 | 40 | button { |
35 | 41 | width: 100%; |
36 | 42 | padding: 12px 20px; |
|
43 | 49 | color: white; |
44 | 50 | transition: background-color 0.3s; |
45 | 51 | } |
| 52 | + |
46 | 53 | button:hover { |
47 | 54 | background-color: #a03a3a; |
48 | 55 | } |
| 56 | + |
49 | 57 | input { |
50 | 58 | width: 100%; |
51 | 59 | padding: 12px; |
|
54 | 62 | border-radius: 5px; |
55 | 63 | font-size: 16px; |
56 | 64 | } |
| 65 | + |
57 | 66 | p { |
58 | 67 | line-height: 1.5; |
59 | 68 | } |
| 69 | + |
60 | 70 | a { |
61 | 71 | text-decoration: none; |
62 | 72 | color: white; |
63 | 73 | } |
| 74 | + |
64 | 75 | a.kRxZy-link { |
65 | 76 | color: #4CAF50; |
66 | 77 | font-weight: bold; |
67 | 78 | } |
| 79 | + |
68 | 80 | a.kRxZy-link:hover { |
69 | 81 | color: #388E3C; |
70 | 82 | } |
| 83 | + |
| 84 | + #loggedInContent { |
| 85 | + display: none; |
| 86 | + padding: 20px; |
| 87 | + } |
71 | 88 | </style> |
72 | 89 | <script> |
73 | | - // Generate a random 3-digit number |
74 | | - function generateThreeDigitCode() { |
75 | | - return Math.floor(100 + Math.random() * 900); |
76 | | - } |
77 | | - |
78 | 90 | let secretCode; |
79 | 91 | if (!localStorage.getItem('baseCode')) { |
80 | 92 | secretCode = '972'; |
|
83 | 95 | secretCode = localStorage.getItem('baseCode'); |
84 | 96 | } |
85 | 97 |
|
86 | | - // Generate a key by shifting the baseKey based on the secret code |
87 | 98 | function generateKeyFromCode(code) { |
88 | 99 | const baseKey = 'abcdefghijklmnopqrstuvwxyz0123456789'; |
89 | 100 | let shiftedKey = ''; |
|
94 | 105 | return shiftedKey; |
95 | 106 | } |
96 | 107 |
|
97 | | - // Encode the username using the generated key |
98 | 108 | function encodeUsername(username, key) { |
99 | 109 | const baseKey = 'abcdefghijklmnopqrstuvwxyz0123456789'; |
100 | 110 | let encoded = ''; |
|
109 | 119 | return encoded; |
110 | 120 | } |
111 | 121 |
|
112 | | - // Decode the username using the generated key |
113 | 122 | function decodeUsername(encodedUsername, key) { |
114 | 123 | const baseKey = 'abcdefghijklmnopqrstuvwxyz0123456789'; |
115 | 124 | let decoded = ''; |
|
132 | 141 | const key = generateKeyFromCode(secretCode); |
133 | 142 | const username = decodeUsername(usernameEncoded, key); |
134 | 143 |
|
135 | | - const textElements = document.querySelectorAll('.text'); |
136 | | - const loggedIn = document.getElementById('loggedIn'); |
137 | | - const tlogged = document.getElementById('hide'); |
138 | | - const mainText = document.getElementById('mainText'); |
139 | | - |
140 | | - // Hide all elements with the class "text" |
141 | | - textElements.forEach(function (element) { |
142 | | - element.style.display = 'none'; |
143 | | - }); |
| 144 | + document.getElementById('authSection').style.display = 'none'; |
| 145 | + document.getElementById('loggedInContent').style.display = 'block'; |
| 146 | + document.getElementById('welcomeMessage').textContent = `Welcome to your account, ${username}!`; |
144 | 147 |
|
145 | 148 | const res = await fetch(`https://scratchgems.onrender.com/api/data/${username}`); |
146 | | - if (!res.ok) { |
147 | | - throw new Error('Failed to fetch data'); |
148 | | - } |
149 | | - const data = await res.json(); |
| 149 | + if (!res.ok) throw new Error('Failed to fetch data'); |
150 | 150 |
|
151 | | - // Show the welcome message |
152 | | - loggedIn.style.display = 'block'; |
153 | | - loggedIn.textContent = `Welcome to your account, ${username}!`; |
154 | | - tlogged.style.display = 'none'; |
155 | | - |
156 | | - if (data && data.pendingorders !== undefined && data.completedorders !== undefined) { |
157 | | - mainText.innerHTML = ` |
158 | | - <p>Pending Orders: ${data.pendingorders}</p> |
159 | | - <br> |
160 | | - <p>Completed Orders: ${data.completedorders}</p> |
161 | | - <br> |
162 | | - `; |
163 | | - } else { |
164 | | - mainText.innerHTML = `<p>Error loading order data.</p>`; |
165 | | - } |
| 151 | + const data = await res.json(); |
| 152 | + document.getElementById('mainText').innerHTML = ` |
| 153 | + <p>Pending Orders: ${data.pendingorders}</p> |
| 154 | + <p>Completed Orders: ${data.completedorders}</p> |
| 155 | + `; |
166 | 156 | } else { |
167 | 157 | checkAuth(); |
168 | 158 | } |
169 | 159 | } catch (error) { |
170 | 160 | console.error(error); |
171 | | - const mainText = document.getElementById('mainText'); |
172 | | - mainText.innerHTML = `<p>Something went wrong! Please try again later.</p>`; |
| 161 | + document.getElementById('mainText').innerHTML = `<p>Something went wrong! Please try again later.</p>`; |
173 | 162 | } |
174 | 163 | }; |
175 | 164 |
|
176 | | - // Check for authentication on page load |
177 | 165 | function checkAuth() { |
178 | 166 | const urlParams = new URLSearchParams(window.location.search); |
179 | 167 | const authSuccess = urlParams.get('success'); |
|
182 | 170 | if (username) { |
183 | 171 | const key = generateKeyFromCode(secretCode); |
184 | 172 | const encodedUsername = encodeUsername(username.toLowerCase(), key); |
185 | | - |
186 | 173 | localStorage.setItem('username', encodedUsername); |
187 | 174 | localStorage.setItem('loggedIn', 'true'); |
188 | 175 | window.location.href = 'index.html'; |
|
194 | 181 | } |
195 | 182 | } |
196 | 183 |
|
197 | | - // Redirect to ScratchAuth for authentication |
198 | 184 | function registerScratchAuth() { |
199 | 185 | const messageBox = document.getElementById("scratchMessage"); |
200 | 186 | const redirectLocation = encodeURIComponent(window.location.href); |
201 | | - |
202 | 187 | const authUrl = `https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&name=Coding%20Hut&sign_in_method=cloud`; |
203 | 188 |
|
204 | 189 | messageBox.style.color = "green"; |
205 | 190 | messageBox.textContent = "Redirecting to ScratchAuth... Follow the steps there."; |
206 | | - |
207 | 191 | setTimeout(() => { |
208 | 192 | window.location.href = authUrl; |
209 | 193 | }, 2000); |
210 | 194 | } |
211 | 195 |
|
212 | | - // Redirect to APIAuth for authentication |
213 | 196 | function registerApiAuth() { |
214 | 197 | const messageBox = document.getElementById("apiMessage"); |
215 | 198 | const redirectLocation = encodeURIComponent(window.location.href); |
216 | | - |
217 | 199 | const authUrl = `https://ubbload.netlify.app/login?redirect=${redirectLocation}&code=${secretCode}`; |
218 | 200 |
|
219 | 201 | messageBox.style.color = "green"; |
220 | 202 | messageBox.textContent = "Redirecting to APIAuth login (ubbload)... Follow the steps there."; |
221 | | - |
222 | 203 | setTimeout(() => { |
223 | 204 | window.location.href = authUrl; |
224 | 205 | }, 2000); |
225 | 206 | } |
226 | 207 |
|
227 | | - // Logout function |
228 | 208 | function logout() { |
229 | 209 | localStorage.removeItem('loggedIn'); |
230 | 210 | localStorage.removeItem('username'); |
231 | 211 | window.location.href = 'login.html'; |
232 | 212 | } |
233 | 213 | </script> |
234 | 214 | </head> |
| 215 | + |
235 | 216 | <body> |
236 | 217 | <!-- Header Content --> |
237 | | - <div class="text header"> |
| 218 | + <div class="header"> |
238 | 219 | <h1>Scratch Authentication</h1> |
239 | 220 | </div> |
240 | | - <div id="loggedIn" class="header" style="display: none;"> |
241 | | - <button onclick="logout()">Logout</button> |
242 | | - </div> |
243 | 221 |
|
244 | | - <!-- Main Content --> |
245 | | - <div id="mainText" class="text content" ></div> |
246 | | - <div id="hide" class="text content"> |
247 | | - <div class="text content"> |
248 | | - <h2>Welcome! Please log in to continue.</h2> |
249 | | - <button onclick="registerScratchAuth()">Sign In With ScratchAuth</button> |
250 | | - <p id="scratchMessage" class="message" aria-live="polite"></p> |
251 | | - <p> |
252 | | - Please note: You will be redirected to an external site (ScratchAuth) for authentication. Once there, |
253 | | - choose the "Cloud Data" option for the quickest sign-in method. |
254 | | - </p> |
| 222 | + <!-- Logged In Section --> |
| 223 | + <div id="loggedInContent"> |
| 224 | + <div class="container"> |
| 225 | + <h2 id="welcomeMessage"></h2> |
| 226 | + <div id="mainText"></div> |
| 227 | + <button onclick="logout()">Logout</button> |
255 | 228 | </div> |
| 229 | + </div> |
| 230 | + |
| 231 | + <!-- Auth Section --> |
| 232 | + <div id="authSection" class="content"> |
| 233 | + <h2>Welcome! Please log in to continue.</h2> |
| 234 | + <button onclick="registerScratchAuth()">Sign In With ScratchAuth</button> |
| 235 | + <p id="scratchMessage" class="message" aria-live="polite"></p> |
| 236 | + <p>Please note: You will be redirected to an external site (ScratchAuth) for authentication.</p> |
256 | 237 |
|
257 | | - <!-- APIAuth Section --> |
258 | | - <div class="text container"> |
| 238 | + <div class="container"> |
259 | 239 | <h2>Login Using APIAuth</h2> |
260 | 240 | <button onclick="registerApiAuth()">Login With APIAuth (Made by |
261 | 241 | <a href="https://scratch.mit.edu/users/kRxZy_kRxZy/" target="_blank" class="kRxZy-link">kRxZy_kRxZy</a>)</button> |
262 | 242 | <p id="apiMessage" class="message" aria-live="polite"></p> |
263 | | - <p> |
264 | | - APIAuth, made by <a href="https://scratch.mit.edu/users/kRxZy_kRxZy/" target="_blank" class="kRxZy-link">kRxZy_kRxZy</a>, is the next generation of Scratch Authentication. |
265 | | - </p> |
266 | 243 | </div> |
267 | 244 |
|
268 | | - <!-- Report Issue Section --> |
269 | | - <div class="text container"> |
| 245 | + <div class="container"> |
270 | 246 | <a href="https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/issues/new"> |
271 | 247 | <button>Having trouble signing in? Report an issue</button> |
272 | 248 | </a> |
273 | 249 | </div> |
274 | 250 | </div> |
275 | 251 | </body> |
| 252 | + |
276 | 253 | </html> |
0 commit comments