mirror of
https://github.com/hyzendust/hyzendust.github.io.git
synced 2026-07-01 07:22:17 +02:00
122 lines
5.3 KiB
HTML
122 lines
5.3 KiB
HTML
{{ define "main" }}
|
|
<div class="auth-page">
|
|
<h1 class="auth-page__title">{{ .Title }}</h1>
|
|
|
|
<div class="auth-card">
|
|
<div id="auth-message" class="auth-message" aria-live="polite" style="display:none"></div>
|
|
|
|
<form id="login-form" class="auth-form" novalidate>
|
|
<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
|
|
placeholder="your_username"
|
|
/>
|
|
</div>
|
|
|
|
<div class="auth-form__group">
|
|
<label class="auth-form__label" for="login-password">Password</label>
|
|
<div class="auth-form__input-wrap">
|
|
<input
|
|
class="auth-form__input"
|
|
type="password"
|
|
id="login-password"
|
|
name="password"
|
|
autocomplete="current-password"
|
|
required
|
|
placeholder="••••••••"
|
|
/>
|
|
<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">
|
|
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';
|
|
|
|
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');
|
|
|
|
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;
|
|
msgBox.style.display = 'block';
|
|
}
|
|
|
|
form.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
msgBox.style.display = 'none';
|
|
|
|
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);
|
|
setTimeout(function () { window.location.href = 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 }}
|