Create login.html
Browse files- login.html +180 -0
login.html
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8" />
|
5 |
+
<meta name="viewport" content="width=device-width" />
|
6 |
+
<title>Dynamic Highscores Login</title>
|
7 |
+
<script src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
|
8 |
+
<script type="importmap">
|
9 |
+
{
|
10 |
+
"imports": {
|
11 |
+
"@huggingface/hub": "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm"
|
12 |
+
}
|
13 |
+
}
|
14 |
+
</script>
|
15 |
+
<style>
|
16 |
+
body {
|
17 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
18 |
+
background-color: #f5f5f5;
|
19 |
+
display: flex;
|
20 |
+
flex-direction: column;
|
21 |
+
align-items: center;
|
22 |
+
justify-content: center;
|
23 |
+
height: 100vh;
|
24 |
+
margin: 0;
|
25 |
+
padding: 20px;
|
26 |
+
}
|
27 |
+
.card {
|
28 |
+
background: white;
|
29 |
+
border-radius: 8px;
|
30 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
31 |
+
padding: 30px;
|
32 |
+
max-width: 500px;
|
33 |
+
width: 100%;
|
34 |
+
text-align: center;
|
35 |
+
}
|
36 |
+
h1 {
|
37 |
+
color: #333;
|
38 |
+
margin-top: 0;
|
39 |
+
}
|
40 |
+
.signin-btn {
|
41 |
+
cursor: pointer;
|
42 |
+
display: block;
|
43 |
+
margin: 20px auto;
|
44 |
+
transition: transform 0.3s ease;
|
45 |
+
}
|
46 |
+
.signin-btn:hover {
|
47 |
+
transform: scale(1.05);
|
48 |
+
}
|
49 |
+
.hidden {
|
50 |
+
display: none;
|
51 |
+
}
|
52 |
+
#status {
|
53 |
+
margin-top: 20px;
|
54 |
+
padding: 10px;
|
55 |
+
border-radius: 4px;
|
56 |
+
}
|
57 |
+
.success {
|
58 |
+
background-color: #d4edda;
|
59 |
+
color: #155724;
|
60 |
+
}
|
61 |
+
.loading {
|
62 |
+
background-color: #fff3cd;
|
63 |
+
color: #856404;
|
64 |
+
}
|
65 |
+
a.button {
|
66 |
+
display: inline-block;
|
67 |
+
background-color: #3498db;
|
68 |
+
color: white;
|
69 |
+
padding: 10px 20px;
|
70 |
+
border-radius: 4px;
|
71 |
+
text-decoration: none;
|
72 |
+
font-weight: bold;
|
73 |
+
margin-top: 20px;
|
74 |
+
}
|
75 |
+
a.button:hover {
|
76 |
+
background-color: #2980b9;
|
77 |
+
}
|
78 |
+
</style>
|
79 |
+
</head>
|
80 |
+
<body>
|
81 |
+
<div class="card">
|
82 |
+
<h1>Dynamic Highscores</h1>
|
83 |
+
<p>Sign in with your HuggingFace account to submit models and benchmarks.</p>
|
84 |
+
|
85 |
+
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-xl-dark.svg"
|
86 |
+
alt="Sign in with Hugging Face"
|
87 |
+
class="signin-btn"
|
88 |
+
id="signin">
|
89 |
+
|
90 |
+
<div id="status" class="hidden"></div>
|
91 |
+
|
92 |
+
<a href="/app" class="button hidden" id="continue-btn">Continue to Dynamic Highscores</a>
|
93 |
+
</div>
|
94 |
+
|
95 |
+
<script type="module">
|
96 |
+
import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub";
|
97 |
+
|
98 |
+
const statusElement = document.getElementById("status");
|
99 |
+
const signinButton = document.getElementById("signin");
|
100 |
+
const continueButton = document.getElementById("continue-btn");
|
101 |
+
|
102 |
+
// Function to show status message
|
103 |
+
function showStatus(message, type) {
|
104 |
+
statusElement.textContent = message;
|
105 |
+
statusElement.className = type;
|
106 |
+
statusElement.classList.remove("hidden");
|
107 |
+
}
|
108 |
+
|
109 |
+
// Check if we're returning from OAuth redirect
|
110 |
+
async function checkLogin() {
|
111 |
+
try {
|
112 |
+
showStatus("Checking login status...", "loading");
|
113 |
+
|
114 |
+
// Check if we already have OAuth data in localStorage
|
115 |
+
let oauthResult = localStorage.getItem("oauth");
|
116 |
+
if (oauthResult) {
|
117 |
+
try {
|
118 |
+
oauthResult = JSON.parse(oauthResult);
|
119 |
+
} catch {
|
120 |
+
oauthResult = null;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
// If not, check if we're returning from a redirect
|
125 |
+
if (!oauthResult) {
|
126 |
+
oauthResult = await oauthHandleRedirectIfPresent();
|
127 |
+
}
|
128 |
+
|
129 |
+
// If we have OAuth data, we're logged in
|
130 |
+
if (oauthResult) {
|
131 |
+
localStorage.setItem("oauth", JSON.stringify(oauthResult));
|
132 |
+
|
133 |
+
signinButton.classList.add("hidden");
|
134 |
+
showStatus(`Logged in as ${oauthResult.userInfo.name}`, "success");
|
135 |
+
continueButton.classList.remove("hidden");
|
136 |
+
|
137 |
+
// Send user info to backend
|
138 |
+
try {
|
139 |
+
await fetch("/api/register_user", {
|
140 |
+
method: "POST",
|
141 |
+
headers: {
|
142 |
+
"Content-Type": "application/json",
|
143 |
+
},
|
144 |
+
body: JSON.stringify({
|
145 |
+
username: oauthResult.userInfo.name,
|
146 |
+
token: oauthResult.accessToken
|
147 |
+
}),
|
148 |
+
});
|
149 |
+
} catch (error) {
|
150 |
+
console.error("Error registering user:", error);
|
151 |
+
}
|
152 |
+
} else {
|
153 |
+
statusElement.classList.add("hidden");
|
154 |
+
signinButton.classList.remove("hidden");
|
155 |
+
}
|
156 |
+
} catch (error) {
|
157 |
+
console.error("Error checking login:", error);
|
158 |
+
showStatus("Error checking login status", "error");
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
// Setup sign in button
|
163 |
+
signinButton.addEventListener("click", async () => {
|
164 |
+
try {
|
165 |
+
showStatus("Redirecting to HuggingFace login...", "loading");
|
166 |
+
window.location.href = await oauthLoginUrl({
|
167 |
+
redirectUrl: window.location.href,
|
168 |
+
scopes: ["openid", "profile"]
|
169 |
+
});
|
170 |
+
} catch (error) {
|
171 |
+
console.error("Error generating login URL:", error);
|
172 |
+
showStatus("Error starting login process", "error");
|
173 |
+
}
|
174 |
+
});
|
175 |
+
|
176 |
+
// Check login status when page loads
|
177 |
+
checkLogin();
|
178 |
+
</script>
|
179 |
+
</body>
|
180 |
+
</html>
|