Skip to content

Commit 482e143

Browse files
authored
Update account.html
Made this thing work again because Github didn't serve my PHP.
1 parent 2523817 commit 482e143

File tree

1 file changed

+21
-122
lines changed

1 file changed

+21
-122
lines changed

account.html

Lines changed: 21 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -11,97 +11,22 @@
1111
padding: 0;
1212
background-color: #f4f4f4;
1313
}
14-
1514
.header {
1615
background-color: #c04d4d;
1716
color: white;
1817
text-align: center;
1918
padding: 20px;
2019
}
21-
22-
.header h1 {
23-
margin: 0;
24-
}
25-
26-
.menu-container {
27-
position: relative;
28-
display: flex;
29-
justify-content: space-between;
30-
background: #c04d4d;
31-
padding: 20px;
32-
color: #fff;
33-
box-sizing: border-box;
34-
}
35-
36-
.menu-logo img {
37-
max-height: 40px;
38-
max-width: 100px;
39-
}
40-
41-
.menu-container a {
42-
text-decoration: none;
43-
color: #ffffff;
44-
transition: color 0.3s ease;
45-
}
46-
47-
.menu-container a:hover {
48-
color: #50e3c2;
49-
}
50-
51-
.menu ul {
52-
list-style: none;
53-
display: flex;
54-
padding: 0;
55-
margin: 0;
56-
}
57-
58-
.menu li {
59-
padding: 0 20px;
60-
font-size: 22px;
61-
}
62-
6320
.content {
6421
padding: 20px;
6522
text-align: center;
6623
}
67-
68-
.logout-btn {
69-
background-color: #c04d4d;
70-
color: white;
71-
padding: 10px 20px;
72-
border: none;
73-
cursor: pointer;
74-
font-size: 16px;
75-
margin-top: 20px;
76-
}
77-
78-
.logout-btn:hover {
79-
background-color: #a03b3b;
80-
}
81-
82-
/* Form Styles */
83-
input[type="text"] {
24+
input[type="text"], button {
8425
padding: 10px;
8526
margin: 10px 0;
8627
font-size: 16px;
87-
border: 1px solid #ccc;
88-
width: 250px;
89-
border-radius: 4px;
90-
}
91-
92-
button {
93-
background-color: #50e3c2;
94-
color: white;
95-
padding: 10px 20px;
96-
font-size: 16px;
97-
border: none;
98-
cursor: pointer;
9928
border-radius: 4px;
10029
}
101-
102-
button:hover {
103-
background-color: #3ec1a0;
104-
}
10530
</style>
10631
<script>
10732
async function registerUser() {
@@ -110,88 +35,62 @@
11035
alert("Please enter a Scratch username.");
11136
return;
11237
}
113-
114-
const response = await fetch("server.php", {
115-
method: "POST",
116-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
117-
body: `username=${encodeURIComponent(username)}`
118-
});
119-
120-
const data = await response.json();
121-
if (data.error) {
122-
alert(data.error);
123-
} else {
124-
localStorage.setItem("privateKey", data.privateKey);
125-
alert("Your private key has been generated and saved locally. Keep it safe!");
126-
}
38+
39+
const privateKey = Math.random().toString(36).substr(2, 10);
40+
localStorage.setItem("privateKey", privateKey);
41+
alert(`Post this key on your Scratch profile: ${privateKey}`);
12742
}
12843

12944
async function authenticateUser() {
45+
const username = document.getElementById("username").value.trim();
13046
const privateKey = localStorage.getItem("privateKey");
131-
if (!privateKey) {
132-
alert("No private key found. Please register first.");
47+
if (!username || !privateKey) {
48+
alert("Make sure you have registered and saved your key.");
13349
return;
13450
}
135-
136-
const response = await fetch("server.php", {
137-
method: "POST",
138-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
139-
body: `challengeResponse=${btoa(privateKey)}`
140-
});
141-
51+
52+
const response = await fetch(`https://api.scratch.mit.edu/users/${username}/`);
14253
const data = await response.json();
143-
if (data.success) {
54+
55+
if (data.profile?.bio.includes(privateKey)) {
14456
alert("Authentication successful!");
145-
window.location.href = "#dashboard"; // Redirect to dashboard
57+
document.getElementById("login").style.display = "none";
58+
document.getElementById("dashboard").style.display = "block";
14659
} else {
147-
alert(data.error);
60+
alert("Key not found in bio. Make sure you've posted it and try again.");
14861
}
14962
}
15063

15164
function logout() {
152-
// Clear the private key from local storage
15365
localStorage.removeItem("privateKey");
154-
155-
// Redirect to login page
156-
window.location.href = "#login"; // Redirect to login page
66+
document.getElementById("dashboard").style.display = "none";
67+
document.getElementById("login").style.display = "block";
15768
}
15869
</script>
15970
</head>
16071
<body>
161-
<!-- Login Form -->
16272
<div id="login">
16373
<div class="header">
16474
<h1>Scratch Authentication</h1>
16575
</div>
166-
16776
<div class="content">
16877
<label for="username">Scratch Username:</label>
16978
<input type="text" id="username" placeholder="Enter your Scratch username" />
17079
<br />
17180
<button onclick="registerUser()">Register</button>
17281
<br /><br />
173-
<button onclick="authenticateUser()">Login with Key</button>
82+
<button onclick="authenticateUser()">Login with Scratch</button>
17483
</div>
17584
</div>
176-
177-
<!-- Dashboard -->
85+
17886
<div id="dashboard" style="display: none;">
17987
<div class="header">
18088
<h1>Welcome to Your Dashboard!</h1>
18189
</div>
182-
18390
<div class="content">
184-
<p>You're successfully logged in with your private key. You can now access your personalized settings and manage your account.</p>
185-
<button class="logout-btn" onclick="logout()">Logout</button>
91+
<p>You're successfully logged in!</p>
92+
<button onclick="logout()">Logout</button>
18693
</div>
18794
</div>
188-
189-
<script>
190-
// Check if user is already authenticated
191-
if (localStorage.getItem("privateKey")) {
192-
document.getElementById("login").style.display = "none";
193-
document.getElementById("dashboard").style.display = "block";
194-
}
195-
</script>
19695
</body>
19796
</html>

0 commit comments

Comments
 (0)