Skip to content

Commit fa1717c

Browse files
authored
Update account.html
1 parent af142ce commit fa1717c

File tree

1 file changed

+37
-63
lines changed

1 file changed

+37
-63
lines changed

account.html

Lines changed: 37 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -63,84 +63,61 @@
6363
}
6464
</style>
6565
<script>
66-
const serverUrl = 'https://image-hoster.onrender.com';
67-
66+
// Function to redirect user to ScratchAuth for authentication
6867
function registerScratchAuth() {
6968
const messageBox = document.getElementById("message");
70-
const redirectLocation = encodeURIComponent(window.location.href);
69+
const redirectLocation = encodeURIComponent(window.location.href); // Redirect back to this page after login
70+
71+
// URL for ScratchAuth with redirect parameter
7172
const authUrl = `https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&name=Coding%20Hut&sign_in_method=cloud`;
7273

7374
messageBox.style.color = "green";
74-
messageBox.textContent = "Redirecting to Scratch Auth... Follow the steps there.";
75+
messageBox.textContent = "Redirecting to ScratchAuth... Follow the steps there.";
76+
77+
setTimeout(() => {
78+
window.location.href = authUrl; // Redirect to ScratchAuth login page
79+
}, 2000);
80+
}
81+
82+
// Function to redirect user to ubbload.netlify.app for APIAuth login
83+
function registerApiAuth() {
84+
const messageBox = document.getElementById("message");
85+
const redirectLocation = encodeURIComponent(window.location.href); // Redirect back to this page after login
86+
87+
// URL for ubbload login, with redirect URL as a query parameter
88+
const authUrl = `https://ubbload.netlify.app/login?redirect=${redirectLocation}`;
89+
90+
messageBox.style.color = "green";
91+
messageBox.textContent = "Redirecting to APIAuth login (ubbload)... Follow the steps there.";
7592

7693
setTimeout(() => {
77-
window.location.href = authUrl;
94+
window.location.href = authUrl; // Redirect to ubbload login page
7895
}, 2000);
7996
}
8097

98+
// Function to handle successful login (after redirect from ScratchAuth or ubbload)
8199
function checkAuth() {
82100
const urlParams = new URLSearchParams(window.location.search);
83101
const authSuccess = urlParams.get('success');
84-
const username = urlParams.get('username');
102+
const username = urlParams.get('username'); // Get the username parameter from the URL
85103

86104
if (username) {
87-
localStorage.setItem('username', username);
105+
localStorage.setItem('username', username); // Store the username in localStorage
106+
localStorage.setItem('loggedIn', 'true'); // Mark the user as logged in
107+
window.location.href = 'index.html'; // Redirect to the main dashboard or home page
88108
}
89-
109+
110+
// If success is true (from ScratchAuth)
90111
if (authSuccess === 'true') {
91112
localStorage.setItem('loggedIn', 'true');
92113
window.location.href = 'index.html';
93114
}
94115
}
95116

96-
window.onload = checkAuth;
117+
window.onload = checkAuth; // Call checkAuth when the page loads to handle login status
97118

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-
}
119+
if (localStorage.getItem('loggedIn') === 'true') {
120+
window.location.href = 'index.html'; // Redirect to the dashboard if already logged in
144121
}
145122
</script>
146123
</head>
@@ -154,23 +131,20 @@ <h2>Welcome! Please log in to continue.</h2>
154131
<button onclick="registerScratchAuth()">Register With ScratchAuth</button>
155132
<p id="message" class="message" aria-live="polite"></p>
156133
<p>
157-
Please note: You will be redirected to an external site (Scratch Auth) for authentication. Once there,
134+
Please note: You will be redirected to an external site (ScratchAuth) for authentication. Once there,
158135
choose the "Cloud Data" option for the quickest sign-in method.
159136
</p>
160137
<p>
161138
If you are unable to use the "Cloud Data" option, other sign-in methods are available on Scratch Auth's page, for example, profile commenting.
162139
</p>
163-
<a href="https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/issues/new">
164-
<button>Having trouble signing in? Report an issue</button>
165-
</a>
140+
166141
</div>
167142

168143
<div class="container">
169144
<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>
145+
<button onclick="registerApiAuth()">Login With APIAuth (Made by <a href="https://scratch.mit.edu/users/kRxZy_kRxZy/" target="_blank" style="color: black">kRxZy_kRxZy</a>)</button>
174146
</div>
147+
<div class="container"><a href="https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/issues/new">
148+
<button>Having trouble signing in? Report an issue</button></a><div>
175149
</body>
176150
</html>

0 commit comments

Comments
 (0)