mirror of
https://github.com/hyzendust/hyzendust.github.io.git
synced 2026-06-30 23:12:16 +02:00
195 lines
6.5 KiB
HTML
195 lines
6.5 KiB
HTML
{{ define "main" }}
|
|
<div class="auth-page">
|
|
<div class="auth-card">
|
|
<h1 class="auth-page__title">{{ .Title }}</h1>
|
|
<div id="auth-message" class="auth-message" aria-live="polite"></div>
|
|
|
|
<form id="login-form" class="auth-form" novalidate>
|
|
<div class="auth-form__input-wrap">
|
|
<div class="auth-form__group">
|
|
<label class="auth-form__label" for="login-username">Username</label>
|
|
<input
|
|
class="auth-form__input"
|
|
type="text"
|
|
id="login-username"
|
|
name="username"
|
|
autocomplete="username"
|
|
required
|
|
/>
|
|
</div>
|
|
|
|
<div class="auth-form__group">
|
|
<label class="auth-form__label" for="login-password">Password</label>
|
|
<input
|
|
class="auth-form__input"
|
|
type="password"
|
|
id="login-password"
|
|
name="password"
|
|
autocomplete="current-password"
|
|
required
|
|
/>
|
|
<button
|
|
type="button"
|
|
class="auth-form__eye"
|
|
aria-label="Toggle password visibility"
|
|
tabindex="-1"
|
|
>
|
|
<svg
|
|
class="eye-show"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 24 24"
|
|
width="16"
|
|
height="16"
|
|
fill="currentColor"
|
|
>
|
|
<path
|
|
d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"
|
|
/>
|
|
</svg>
|
|
<svg
|
|
class="eye-hide"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 24 24"
|
|
width="16"
|
|
height="16"
|
|
fill="currentColor"
|
|
style="display: none"
|
|
>
|
|
<path
|
|
d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"
|
|
/>
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="auth-form__submit" id="login-submit">
|
|
<span class="auth-form__submit-text">Log In</span>
|
|
<span class="auth-form__submit-loader" style="display: none">
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 24 24"
|
|
width="16"
|
|
height="16"
|
|
fill="currentColor"
|
|
class="spin"
|
|
>
|
|
<path
|
|
d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"
|
|
/>
|
|
</svg>
|
|
</span>
|
|
</button>
|
|
</form>
|
|
|
|
<p class="auth-card__footer" id="login-footer">
|
|
Don't have an account? <a href="/signup/" class="auth-card__link">Sign up</a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
(function () {
|
|
var BACKEND = 'https://backend.freedoms4.org/auth.php';
|
|
|
|
// ── Already logged in ──
|
|
if (localStorage.getItem('f4_username')) {
|
|
document.getElementById('auth-message').textContent = 'You are already logged in!';
|
|
document.getElementById('auth-message').className =
|
|
'auth-message auth-message--success is-visible';
|
|
document.getElementById('login-form').style.display = 'none';
|
|
document.getElementById('login-footer').style.display = 'none';
|
|
return;
|
|
}
|
|
|
|
// ── Remember where to go after login ──
|
|
(function () {
|
|
var params = new URLSearchParams(window.location.search);
|
|
var next = params.get('next');
|
|
if (next && next.startsWith('/')) {
|
|
sessionStorage.setItem('f4_login_next', next);
|
|
} else if (!sessionStorage.getItem('f4_login_next') && document.referrer) {
|
|
try {
|
|
var refUrl = new URL(document.referrer);
|
|
if (refUrl.hostname === window.location.hostname) {
|
|
var p = refUrl.pathname;
|
|
if (p !== '/login/' && p !== '/signup/') {
|
|
sessionStorage.setItem('f4_login_next', p);
|
|
}
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
})();
|
|
|
|
var form = document.getElementById('login-form');
|
|
var msgBox = document.getElementById('auth-message');
|
|
var submitBtn = document.getElementById('login-submit');
|
|
var eyeBtn = form.querySelector('.auth-form__eye');
|
|
var pwdInput = document.getElementById('login-password');
|
|
var pwdInput = document.getElementById('login-password');
|
|
|
|
eyeBtn.addEventListener('click', function () {
|
|
var isText = pwdInput.type === 'text';
|
|
pwdInput.type = isText ? 'password' : 'text';
|
|
eyeBtn.querySelector('.eye-show').style.display = isText ? '' : 'none';
|
|
eyeBtn.querySelector('.eye-hide').style.display = isText ? 'none' : '';
|
|
});
|
|
|
|
function showMsg(text, type) {
|
|
msgBox.textContent = text;
|
|
msgBox.className = 'auth-message auth-message--' + type + ' is-visible';
|
|
}
|
|
|
|
form.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
msgBox.className = 'auth-message';
|
|
|
|
var username = document.getElementById('login-username').value.trim();
|
|
var password = pwdInput.value;
|
|
|
|
if (!username || !password) {
|
|
showMsg('Please fill in all fields.', 'error');
|
|
return;
|
|
}
|
|
|
|
submitBtn.disabled = true;
|
|
submitBtn.querySelector('.auth-form__submit-text').style.display = 'none';
|
|
submitBtn.querySelector('.auth-form__submit-loader').style.display = 'inline-flex';
|
|
|
|
fetch(BACKEND, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
credentials: 'include',
|
|
body: JSON.stringify({ action: 'login', username: username, password: password }),
|
|
})
|
|
.then(function (r) {
|
|
return r.json();
|
|
})
|
|
.then(function (data) {
|
|
if (data.success) {
|
|
showMsg('Logged in successfully! Redirecting\u2026', 'success');
|
|
localStorage.setItem('f4_username', username);
|
|
localStorage.setItem('f4_login_time', Date.now());
|
|
setTimeout(function () {
|
|
var _next = sessionStorage.getItem('f4_login_next');
|
|
sessionStorage.removeItem('f4_login_next');
|
|
window.location.href =
|
|
_next && _next.startsWith('/') ? _next : data.redirect || '/';
|
|
}, 1000);
|
|
} else {
|
|
showMsg(data.message || 'Login failed. Please try again.', 'error');
|
|
}
|
|
})
|
|
.catch(function () {
|
|
showMsg('Network error. Please try again.', 'error');
|
|
})
|
|
.finally(function () {
|
|
submitBtn.disabled = false;
|
|
submitBtn.querySelector('.auth-form__submit-text').style.display = '';
|
|
submitBtn.querySelector('.auth-form__submit-loader').style.display = 'none';
|
|
});
|
|
});
|
|
})();
|
|
</script>
|
|
{{ end }}
|