Skip to content

Commit 4bdef20

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

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

account.html

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
}
5454
</style>
5555
<script>
56-
function registerUser() {
56+
function registerScratchAuth() {
5757
const messageBox = document.getElementById("message");
5858

5959
const redirectLocation = encodeURIComponent(window.location.href);
@@ -90,7 +90,27 @@ <h1>Scratch Authentication</h1>
9090
</div>
9191
<div class="content">
9292
<h2>Welcome! Please log in to continue.</h2>
93-
<button onclick="registerUser()">Register</button>
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>
94114
<p id="message" class="message" aria-live="polite"></p>
95115
<p>
96116
Please note: You will be redirected to an external site (Scratch Auth) for authentication. Once there,
@@ -102,6 +122,51 @@ <h2>Welcome! Please log in to continue.</h2>
102122
<a href="https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/issues/new">
103123
<button>Having trouble signing in? Report an issue</button>
104124
</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+
});
160+
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>
105170
</div>
106171
</body>
107172
</html>

0 commit comments

Comments
 (0)