feat: redesign website templates with full pages
- Redesigned base.html: dark Minecraft theme, sticky header, responsive grid, cards, server cards with status indicators, profile styles - index.html: hero section, server list grid, how-to-start steps, features section - login.html: centered card layout, client-side validation, fetch API - registration.html: password confirmation, pattern validation, error alerts - profile.html: new page — skin/cape upload & delete, launcher download links, auth-gated via localStorage token - templates.go: added /profile route, extended pageData with Username/UUID
This commit is contained in:
@@ -1,42 +1,61 @@
|
||||
{{define "content"}}
|
||||
<div class="card">
|
||||
<h1>Вход</h1>
|
||||
<form id="loginForm">
|
||||
<label for="username">Логин или Email</label>
|
||||
<input type="text" id="username" name="username" required autocomplete="username">
|
||||
<div class="container-narrow">
|
||||
<div class="card text-center">
|
||||
<h1 style="margin-bottom:0.5rem">👋 С возвращением</h1>
|
||||
<p class="muted mb-0">Войди в аккаунт, чтобы управлять профилем и скачать лаунчер.</p>
|
||||
</div>
|
||||
|
||||
<label for="password">Пароль</label>
|
||||
<input type="password" id="password" name="password" required autocomplete="current-password">
|
||||
<div class="card">
|
||||
<div id="alert" class="alert alert-error"></div>
|
||||
<form id="loginForm" novalidate>
|
||||
<label for="username">Логин или Email</label>
|
||||
<input type="text" id="username" name="username" required autocomplete="username" placeholder="player или player@email.com">
|
||||
|
||||
<button type="submit" class="btn">Войти</button>
|
||||
</form>
|
||||
<p id="error" style="color: var(--error); margin-top: 0.75rem; display: none;"></p>
|
||||
<p style="margin-top: 1rem;">Нет аккаунта? <a href="/register">Зарегистрироваться</a></p>
|
||||
<label for="password">Пароль</label>
|
||||
<input type="password" id="password" name="password" required autocomplete="current-password" placeholder="••••••••">
|
||||
|
||||
<button type="submit" class="btn" style="width:100%">Войти</button>
|
||||
</form>
|
||||
<p class="text-center mt-2 muted">Нет аккаунта? <a href="/register">Зарегистрироваться</a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
||||
document.getElementById('loginForm').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
const form = new FormData(e.target);
|
||||
const res = await fetch('/api/web/login', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
username: form.get('username'),
|
||||
password: form.get('password')
|
||||
})
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
document.getElementById('error').textContent = data.error || 'Ошибка входа';
|
||||
document.getElementById('error').style.display = 'block';
|
||||
const alert = document.getElementById('alert');
|
||||
alert.className = 'alert alert-error';
|
||||
alert.classList.remove('show');
|
||||
|
||||
const username = document.getElementById('username').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
if (!username || !password) {
|
||||
alert.textContent = 'Заполните все поля';
|
||||
alert.classList.add('show');
|
||||
return;
|
||||
}
|
||||
// Save token to localStorage and redirect.
|
||||
localStorage.setItem('token', data.token);
|
||||
localStorage.setItem('uuid', data.uuid);
|
||||
localStorage.setItem('username', data.username);
|
||||
window.location.href = '/';
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/web/login', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({username, password})
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
alert.textContent = data.error || 'Ошибка входа';
|
||||
alert.classList.add('show');
|
||||
return;
|
||||
}
|
||||
localStorage.setItem('token', data.token);
|
||||
localStorage.setItem('uuid', data.uuid);
|
||||
localStorage.setItem('username', data.username);
|
||||
window.location.href = '/profile';
|
||||
} catch (err) {
|
||||
alert.textContent = 'Ошибка сети. Попробуй ещё раз.';
|
||||
alert.classList.add('show');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user