Skip to content

Commit 2b04f1f

Browse files
authored
Update account.html
1 parent 5a095a4 commit 2b04f1f

File tree

1 file changed

+38
-46
lines changed

1 file changed

+38
-46
lines changed

account.html

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -63,71 +63,64 @@
6363
}
6464
</style>
6565
<script>
66-
// Function to redirect user to ScratchAuth for authentication
66+
window.onload = function() {
67+
if (localStorage.getItem('loggedIn') === 'true') {
68+
const username = localStorage.getItem('username');
69+
const text = document.getElementById('text');
70+
const loggedIn = document.getElementById('loggedIn');
71+
72+
text.style.display = 'none';
73+
loggedIn.style.display = 'block';
74+
loggedIn.textContent = `Welcome to your account ${username}!`;
75+
} else {
76+
checkAuth();
77+
}
78+
};
79+
80+
function checkAuth() {
81+
const urlParams = new URLSearchParams(window.location.search);
82+
const authSuccess = urlParams.get('success');
83+
const username = urlParams.get('username');
84+
85+
if (username) {
86+
localStorage.setItem('username', username);
87+
localStorage.setItem('loggedIn', 'true');
88+
window.location.href = 'index.html';
89+
}
90+
91+
if (authSuccess === 'true') {
92+
localStorage.setItem('loggedIn', 'true');
93+
window.location.href = 'index.html';
94+
}
95+
}
96+
6797
function registerScratchAuth() {
6898
const messageBox = document.getElementById("message");
69-
const redirectLocation = encodeURIComponent(window.location.href); // Redirect back to this page after login
99+
const redirectLocation = encodeURIComponent(window.location.href);
70100

71-
// URL for ScratchAuth with redirect parameter
72101
const authUrl = `https://auth.itinerary.eu.org/auth/?redirect=${redirectLocation}&name=Coding%20Hut&sign_in_method=cloud`;
73102

74103
messageBox.style.color = "green";
75104
messageBox.textContent = "Redirecting to ScratchAuth... Follow the steps there.";
76105

77106
setTimeout(() => {
78-
window.location.href = authUrl; // Redirect to ScratchAuth login page
107+
window.location.href = authUrl;
79108
}, 2000);
80109
}
81110

82-
// Function to redirect user to ubbload.netlify.app for APIAuth login
83111
function registerApiAuth() {
84112
const messageBox = document.getElementById("message");
85-
const redirectLocation = encodeURIComponent(window.location.href); // Redirect back to this page after login
113+
const redirectLocation = encodeURIComponent(window.location.href);
86114

87-
// URL for ubbload login, with redirect URL as a query parameter
88115
const authUrl = `https://ubbload.netlify.app/login?redirect=${redirectLocation}`;
89116

90117
messageBox.style.color = "green";
91118
messageBox.textContent = "Redirecting to APIAuth login (ubbload)... Follow the steps there.";
92119

93120
setTimeout(() => {
94-
window.location.href = authUrl; // Redirect to ubbload login page
121+
window.location.href = authUrl;
95122
}, 2000);
96123
}
97-
98-
// Function to handle successful login (after redirect from ScratchAuth or ubbload)
99-
function checkAuth() {
100-
const urlParams = new URLSearchParams(window.location.search);
101-
const authSuccess = urlParams.get('success');
102-
const username = urlParams.get('username'); // Get the username parameter from the URL
103-
104-
if (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
108-
}
109-
110-
// If success is true (from ScratchAuth)
111-
if (authSuccess === 'true') {
112-
localStorage.setItem('loggedIn', 'true');
113-
window.location.href = 'index.html';
114-
}
115-
}
116-
117-
window.onload = checkAuth; // Call checkAuth when the page loads to handle login status
118-
119-
if (localStorage.getItem('loggedIn') === 'true') {
120-
window.location.href = 'index.html'; // Redirect to the dashboard if already logged in
121-
}
122-
checkAuth()
123-
const user = localStorage.getItem('username')
124-
const text = document.getElementById('text');
125-
const loggedIn = document.getElementById('loggedIn')
126-
if (username) {
127-
text.style.display = 'none';
128-
loggedIn.style.display = 'block';
129-
loggedIn.textContent = `Welcome to your account ${username}!`
130-
}
131124
</script>
132125
</head>
133126
<body>
@@ -145,14 +138,13 @@ <h2>Welcome! Please log in to continue.</h2>
145138
choose the "Cloud Data" option for the quickest sign-in method.
146139

147140
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.</p>
148-
149141
</div>
150142

151143
<div id="text" class="container">
152144
<h2>Login Using APIAuth</h2>
153-
<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>
145+
<button onclick="registerApiAuth()">Login With APIAuth (Made by <a href="https://scratch.mit.edu/users/kRxZy_kRxZy/" target="_blank" style="color: blue">kRxZy_kRxZy</a>)</button>
154146
</div>
155-
<div id="text" class="container"><a href="https://github.com/Scratch-Coding-Hut/Scratch-Coding-Hut.github.io/issues/new">
156-
<button>Having trouble signing in? Report an issue</button></a><div>
147+
<div id="text" 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>
157149
</body>
158150
</html>

0 commit comments

Comments
 (0)