Skip to content

Commit af142ce

Browse files
authored
Update account.html
1 parent 4bdef20 commit af142ce

File tree

1 file changed

+77
-73
lines changed

1 file changed

+77
-73
lines changed

account.html

Lines changed: 77 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<title>Scratch Auth | Login & Dashboard | Coding Hut</title>
77
<style>
88
body {
9-
font-family: 'Arial', sans-serif;
9+
font-family: Arial, sans-serif;
1010
margin: 0;
1111
padding: 0;
1212
background-color: #f4f4f4;
@@ -18,10 +18,10 @@
1818
padding: 20px;
1919
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
2020
}
21-
.content {
21+
.content, .container {
2222
padding: 20px;
2323
max-width: 600px;
24-
margin: auto;
24+
margin: 20px auto;
2525
background-color: white;
2626
border-radius: 8px;
2727
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
@@ -32,8 +32,9 @@
3232
margin-top: 10px;
3333
}
3434
button {
35-
padding: 10px 20px;
36-
margin: 10px;
35+
width: 100%;
36+
padding: 12px 20px;
37+
margin: 10px 0;
3738
font-size: 16px;
3839
border: none;
3940
border-radius: 5px;
@@ -45,22 +46,32 @@
4546
button:hover {
4647
background-color: #a03a3a;
4748
}
49+
input {
50+
width: 100%;
51+
padding: 12px;
52+
margin: 10px 0;
53+
border: 1px solid #ddd;
54+
border-radius: 5px;
55+
font-size: 16px;
56+
}
4857
p {
4958
line-height: 1.5;
5059
}
5160
a {
5261
text-decoration: none;
62+
color: white;
5363
}
5464
</style>
5565
<script>
66+
const serverUrl = 'https://image-hoster.onrender.com';
67+
5668
function registerScratchAuth() {
5769
const messageBox = document.getElementById("message");
58-
5970
const redirectLocation = encodeURIComponent(window.location.href);
6071
const authUrl = `https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&name=Coding%20Hut&sign_in_method=cloud`;
6172

6273
messageBox.style.color = "green";
63-
messageBox.textContent = `Redirecting to Scratch Auth... Follow the steps there.`;
74+
messageBox.textContent = "Redirecting to Scratch Auth... Follow the steps there.";
6475

6576
setTimeout(() => {
6677
window.location.href = authUrl;
@@ -69,8 +80,9 @@
6980

7081
function checkAuth() {
7182
const urlParams = new URLSearchParams(window.location.search);
72-
const authSuccess = urlParams.get('success'); // Example: Scratch Auth might return '?success=true'
83+
const authSuccess = urlParams.get('success');
7384
const username = urlParams.get('username');
85+
7486
if (username) {
7587
localStorage.setItem('username', username);
7688
}
@@ -82,35 +94,64 @@
8294
}
8395

8496
window.onload = checkAuth;
97+
98+
if (localStorage.getItem('verifiedUser')) {
99+
window.location.href = 'index.html';
100+
}
101+
102+
async function login() {
103+
let username = document.getElementById('username').value.trim().toLowerCase();
104+
if (!username) {
105+
alert('Enter your Scratch username.');
106+
return;
107+
}
108+
109+
const response = await fetch(`${serverUrl}/login`, {
110+
method: 'POST',
111+
headers: { 'Content-Type': 'application/json' },
112+
body: JSON.stringify({ username })
113+
});
114+
115+
const result = await response.json();
116+
if (result.verified) {
117+
localStorage.setItem('verifiedUser', username);
118+
window.location.href = 'upload.html';
119+
} else {
120+
document.getElementById('codeMessage').textContent = result.message || 'Login failed. Please try again.';
121+
}
122+
}
123+
124+
async function verifyCode() {
125+
let username = document.getElementById('username').value.trim().toLowerCase();
126+
if (!username) {
127+
alert('Enter your username first.');
128+
return;
129+
}
130+
131+
const response = await fetch(`${serverUrl}/verify`, {
132+
method: 'POST',
133+
headers: { 'Content-Type': 'application/json' },
134+
body: JSON.stringify({ username })
135+
});
136+
137+
const result = await response.json();
138+
if (result.verified) {
139+
localStorage.setItem('verifiedUser', username);
140+
window.location.href = 'index.html';
141+
} else {
142+
alert(result.message || 'Verification failed. Please try again.');
143+
}
144+
}
85145
</script>
86146
</head>
87147
<body>
88148
<div class="header">
89149
<h1>Scratch Authentication</h1>
90150
</div>
151+
91152
<div class="content">
92153
<h2>Welcome! Please log in to continue.</h2>
93-
<button onclick="registerScratchAuth()">Register With ScratchAuth (Currently not working.)</button>
94-
95-
<!DOCTYPE html>
96-
<html lang="en">
97-
<head>
98-
<meta charset="UTF-8">
99-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
100-
<title>Login</title>
101-
<style>
102-
body { font-family: Arial, sans-serif; background: #f4f4f4; display: flex; align-items: center; justify-content: center; height: 100vh; }
103-
.container { background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); text-align: center; width: 350px; }
104-
input, button { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #ddd; border-radius: 5px; font-size: 16px; }
105-
button { background: #007bff; color: white; border: none; cursor: pointer; }
106-
</style>
107-
</head>
108-
<body>
109-
<div class="container">
110-
<button onclick="login()">Login With APIAuth (Made by <a href="scratch.mit.edu/users/kRxZy_kRxZy>kRxZy_kRxZy</a>)</button>
111-
<p id="codeMessage"></p>
112-
<button onclick="verifyCode()">Done</button>
113-
</div>
154+
<button onclick="registerScratchAuth()">Register With ScratchAuth</button>
114155
<p id="message" class="message" aria-live="polite"></p>
115156
<p>
116157
Please note: You will be redirected to an external site (Scratch Auth) for authentication. Once there,
@@ -122,51 +163,14 @@ <h2>Welcome! Please log in to continue.</h2>
122163
<a href="https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/issues/new">
123164
<button>Having trouble signing in? Report an issue</button>
124165
</a>
125-
<script>
126-
const serverUrl = 'https://image-hoster.onrender.com';
127-
128-
if (localStorage.getItem('verifiedUser')) {
129-
window.location.href = 'index';
130-
}
131-
132-
async function login() {
133-
let username = document.getElementById('username').value.trim().toLowerCase();
134-
if (!username) return alert('Enter your Scratch username.');
135-
136-
const response = await fetch(`${serverUrl}/login`, {
137-
method: 'POST',
138-
headers: { 'Content-Type': 'application/json' },
139-
body: JSON.stringify({ username })
140-
});
141-
142-
const result = await response.json();
143-
if (result.verified) {
144-
localStorage.setItem('verifiedUser', username);
145-
window.location.href = 'upload.html';
146-
} else {
147-
document.getElementById('codeMessage').textContent = result.message;
148-
}
149-
}
150-
151-
async function verifyCode() {
152-
let username = document.getElementById('username').value.trim().toLowerCase();
153-
if (!username) return alert('Enter your username first.');
154-
155-
const response = await fetch(`${serverUrl}/verify`, {
156-
method: 'POST',
157-
headers: { 'Content-Type': 'application/json' },
158-
body: JSON.stringify({ username })
159-
});
166+
</div>
160167

161-
const result = await response.json();
162-
if (result.verified) {
163-
localStorage.setItem('verifiedUser', username);
164-
window.location.href = 'index.html';
165-
} else {
166-
alert(result.message || 'Verification failed.');
167-
}
168-
}
169-
</script>
168+
<div class="container">
169+
<h2>Login Using APIAuth</h2>
170+
<input type="text" id="username" placeholder="Enter your Scratch username" />
171+
<button onclick="login()">Login With APIAuth (Made by <a href="https://scratch.mit.edu/users/kRxZy_kRxZy/" target="_blank" style="color: red">kRxZy_kRxZy</a>)</button>
172+
<p id="codeMessage" class="message"></p>
173+
<button onclick="verifyCode()">Verify Code</button>
170174
</div>
171175
</body>
172176
</html>

0 commit comments

Comments
 (0)