Spaces:
Running
Running
File size: 7,267 Bytes
8b9f7d9 81046e2 8b9f7d9 81046e2 8b9f7d9 81046e2 8b9f7d9 643b2e1 8b9f7d9 81046e2 8b9f7d9 643b2e1 8b9f7d9 81046e2 8b9f7d9 643b2e1 8b9f7d9 643b2e1 8b9f7d9 643b2e1 8b9f7d9 81046e2 8b9f7d9 81046e2 8b9f7d9 81046e2 8b9f7d9 81046e2 8b9f7d9 81046e2 8b9f7d9 81046e2 643b2e1 81046e2 643b2e1 8b9f7d9 81046e2 8b9f7d9 d8d032f 8b9f7d9 81046e2 8b9f7d9 d8d032f 8b9f7d9 d8d032f 8b9f7d9 d8d032f 8b9f7d9 643b2e1 8b9f7d9 643b2e1 8b9f7d9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { t, getStoredLang, storeLang } from '../i18n'
import type { Lang } from '../i18n'
const props = defineProps<{
googleClientId: string
lang: Lang
}>()
const emit = defineEmits<{
'google-login': [credential: string]
'update:lang': [lang: Lang]
}>()
const error = ref('')
const loading = ref(false)
// Check if we're inside an iframe (HuggingFace Spaces embeds apps in iframes)
const isInIframe = ref(false)
const directUrl = ref('')
try {
isInIframe.value = window.self !== window.top
} catch {
isInIframe.value = true // cross-origin iframe throws
}
// Build the direct .hf.space URL from the current page
if (isInIframe.value) {
const match = window.location.href.match(/spaces\/([^/]+)\/([^/?#]+)/)
if (match) {
directUrl.value = `https://${match[1].toLowerCase()}-${match[2].toLowerCase().replace(/_/g, '-')}.hf.space`
} else {
directUrl.value = window.location.origin
}
}
function switchLang(lang: Lang) {
storeLang(lang)
emit('update:lang', lang)
}
onMounted(() => {
checkRedirectResult()
if (document.getElementById('gsi-script')) {
initGsi()
return
}
const script = document.createElement('script')
script.id = 'gsi-script'
script.src = 'https://accounts.google.com/gsi/client'
script.async = true
script.defer = true
script.onload = initGsi
script.onerror = () => {
error.value = t('login.error.gsi', props.lang)
}
document.head.appendChild(script)
})
function checkRedirectResult() {
// After Google redirect, the credential comes back as a POST to the current page
}
function initGsi() {
const w = window as any
if (!w.google?.accounts?.id) {
setTimeout(initGsi, 100)
return
}
w.google.accounts.id.initialize({
client_id: props.googleClientId,
callback: handleCredentialResponse,
auto_select: false,
ux_mode: isInIframe.value ? 'redirect' : 'popup',
login_uri: isInIframe.value ? (directUrl.value || window.location.origin) + '/' : undefined,
})
w.google.accounts.id.renderButton(
document.getElementById('g-signin-btn'),
{
theme: 'filled_black',
size: 'large',
shape: 'rectangular',
text: 'signin_with',
width: 300,
}
)
}
function handleCredentialResponse(response: { credential: string }) {
if (response.credential) {
loading.value = true
emit('google-login', response.credential)
} else {
error.value = t('login.error.failed', props.lang)
}
}
</script>
<template>
<div class="login-page">
<div class="login-card">
<!-- Language toggle (top-right of card) -->
<div class="lang-toggle">
<button
:class="['lang-btn', { active: lang === 'en' }]"
@click="switchLang('en')"
>EN</button>
<span class="lang-sep">|</span>
<button
:class="['lang-btn', { active: lang === 'hr' }]"
@click="switchLang('hr')"
>HR</button>
</div>
<!-- WC3-style frame -->
<div class="login-frame">
<div class="login-icon">⚔️</div>
<h1>{{ t('login.title', lang) }}</h1>
<p class="subtitle">{{ t('login.subtitle', lang) }}</p>
<div class="gold-divider"></div>
<p class="login-prompt">{{ t('login.prompt', lang) }}</p>
<!-- Google Sign-In button renders here -->
<div id="g-signin-btn" class="g-btn-container"></div>
<p v-if="loading" class="login-loading">{{ t('login.loading', lang) }}</p>
<p v-if="error" class="login-error">{{ error }}</p>
<!-- Iframe hint -->
<p v-if="isInIframe" class="iframe-hint">
{{ t('login.iframe.hint', lang) }}<br>
<a :href="directUrl" target="_top" class="direct-link">{{ directUrl }}</a>
</p>
<div class="gold-divider"></div>
<p class="login-footer">
{{ t('login.footer.powered', lang) }}<br>
<span class="login-footer-dim">{{ t('login.footer.edition', lang) }}</span>
</p>
</div>
</div>
</div>
</template>
<style lang="scss">
.login-page {
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: radial-gradient(ellipse at center, #12122a 0%, #0a0a16 50%, #050510 100%);
}
.login-card {
width: 100%;
max-width: 480px;
padding: 2rem;
position: relative;
}
/* ---- Language Toggle ---- */
.lang-toggle {
display: flex;
align-items: center;
justify-content: center;
gap: 0.25rem;
margin-bottom: 0.75rem;
}
.lang-btn {
background: none;
border: 1px solid transparent;
color: var(--wc3-text-dim, #7a6e5a);
font-family: var(--font-heading, 'Cinzel', serif);
font-size: 0.8rem;
letter-spacing: 1.5px;
padding: 0.3rem 0.75rem;
cursor: pointer;
border-radius: 3px;
transition: all 0.15s;
}
.lang-btn:hover {
color: var(--wc3-gold, #c8aa6e);
border-color: var(--wc3-gold-dim, #8b7b4f);
}
.lang-btn.active {
color: var(--wc3-gold-bright, #f0d060);
border-color: var(--wc3-gold, #c8aa6e);
background: rgba(200, 170, 110, 0.08);
text-shadow: 0 0 8px rgba(200, 170, 110, 0.3);
}
.lang-sep {
color: var(--wc3-border, #5a4a2a);
font-size: 0.8rem;
}
.login-frame {
background: linear-gradient(180deg, #13132a 0%, #0d0d1f 100%);
border: 2px solid var(--wc3-gold-dim, #8b7b4f);
border-radius: 6px;
padding: 2.5rem 2rem;
text-align: center;
box-shadow:
0 0 40px rgba(200, 170, 110, 0.08),
inset 0 1px 0 rgba(200, 170, 110, 0.1);
}
.login-icon {
font-size: 3rem;
margin-bottom: 0.75rem;
filter: drop-shadow(0 0 10px rgba(200, 170, 110, 0.4));
}
.login-frame h1 {
font-family: var(--font-display, 'Cinzel Decorative', serif);
font-size: 1.5rem;
font-weight: 900;
background: linear-gradient(180deg, #f0d060 0%, #c8aa6e 50%, #8b7b4f 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
letter-spacing: 1px;
margin-bottom: 0.25rem;
word-break: keep-all;
}
.login-frame .subtitle {
font-family: var(--font-body, 'Crimson Text', serif);
color: var(--wc3-text-dim, #7a6e5a);
font-style: italic;
font-size: 0.95rem;
}
.login-prompt {
font-family: var(--font-heading, 'Cinzel', serif);
color: var(--wc3-gold, #c8aa6e);
font-size: 0.9rem;
letter-spacing: 1.5px;
text-transform: uppercase;
margin-bottom: 1.25rem;
}
.g-btn-container {
display: flex;
justify-content: center;
min-height: 44px;
margin-bottom: 0.5rem;
}
.login-loading {
color: var(--wc3-gold, #c8aa6e);
font-size: 0.85rem;
margin-top: 0.75rem;
animation: pulse 1.5s ease-in-out infinite;
}
.login-error {
color: #ff6666;
font-size: 0.85rem;
margin-top: 0.75rem;
}
.iframe-hint {
color: var(--wc3-text-dim, #7a6e5a);
font-size: 0.78rem;
margin-top: 1rem;
line-height: 1.6;
}
.direct-link {
color: var(--wc3-gold, #c8aa6e);
text-decoration: underline;
text-underline-offset: 2px;
word-break: break-all;
}
.direct-link:hover {
color: var(--wc3-gold-bright, #f0d060);
}
.login-footer {
font-size: 0.8rem;
color: var(--wc3-text-dim, #7a6e5a);
font-style: italic;
line-height: 1.6;
}
.login-footer-dim {
color: var(--wc3-text-muted, #555060);
font-size: 0.75rem;
}
</style>
|