v9 — логин и пароль при регистрации и входе
This commit is contained in:
parent
d814f28513
commit
6e68eed378
84
index.html
84
index.html
@ -103,7 +103,7 @@ input[type=file]{display:none}
|
||||
|
||||
.app-screen{display:none}
|
||||
.app-screen.active{display:block}
|
||||
.profile-screen.hidden{display:none}
|
||||
.profile-screen.hidden,#loginScreen.hidden{display:none}
|
||||
|
||||
@media(max-width:480px){
|
||||
.grid2{grid-template-columns:1fr}
|
||||
@ -117,13 +117,33 @@ input[type=file]{display:none}
|
||||
<body>
|
||||
|
||||
<!-- PROFILE SCREEN -->
|
||||
<div class="profile-screen" id="profileScreen">
|
||||
<!-- LOGIN SCREEN -->
|
||||
<div class="profile-screen" id="loginScreen">
|
||||
<div style="max-width:400px;margin:auto">
|
||||
<h2>🏊 <span>Галикон</span></h2>
|
||||
<p class="sub">Войди в свой аккаунт</p>
|
||||
<div class="card">
|
||||
<input type="text" id="loginUser" placeholder="Логин">
|
||||
<input type="password" id="loginPass" placeholder="Пароль">
|
||||
<div id="loginError" style="color:var(--red);font-size:13px;margin-bottom:8px;display:none"></div>
|
||||
<button class="btn" onclick="doLogin()" style="width:100%;margin-bottom:8px">🔒 Войти</button>
|
||||
<button class="btn outline" onclick="showRegister()" style="width:100%">✏ Создать аккаунт</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- REGISTER + PROFILE SCREEN -->
|
||||
<div class="profile-screen hidden" id="profileScreen">
|
||||
<h2>🏊 <span>Галикон</span></h2>
|
||||
<p class="sub">Приложение для спортсменов. Создай свой профиль.</p>
|
||||
|
||||
<div class="card" id="regForm">
|
||||
<h3>✏ Регистрация</h3>
|
||||
<input type="text" id="regName" placeholder="Фамилия Имя Отчество">
|
||||
<div class="grid2">
|
||||
<input type="text" id="regLogin" placeholder="Придумай логин">
|
||||
<input type="password" id="regPass" placeholder="Придумай пароль">
|
||||
</div>
|
||||
<div class="grid2">
|
||||
<select id="regSport">
|
||||
<option value="">Выбери вид спорта</option>
|
||||
@ -198,6 +218,7 @@ input[type=file]{display:none}
|
||||
<header>
|
||||
<h1>🏊 <span>Галикон</span></h1>
|
||||
<div class="header-right">
|
||||
<button class="btn outline small" style="padding:4px 10px;font-size:11px;margin-right:4px" onclick="doLogout()">🚪</button>
|
||||
<span class="profile-name" id="headerName"></span>
|
||||
<div class="avatar" id="headerAvatar" onclick="showProfileScreen()"></div>
|
||||
</div>
|
||||
@ -373,8 +394,54 @@ function toast(msg) {
|
||||
}
|
||||
|
||||
// === PROFILE SYSTEM ===
|
||||
function doLogin() {
|
||||
const login = document.getElementById('loginUser').value.trim().toLowerCase();
|
||||
const pass = document.getElementById('loginPass').value;
|
||||
if (!login || !pass) { showLoginError('Введи логин и пароль!'); return; }
|
||||
const profiles = LS('profiles') || [];
|
||||
const profile = profiles.find(p => p.login === login && p.pass === pass);
|
||||
if (!profile) { showLoginError('Неверный логин или пароль'); return; }
|
||||
document.getElementById('loginScreen').classList.add('hidden');
|
||||
document.getElementById('profileScreen').classList.add('hidden');
|
||||
document.getElementById('loginScreen').classList.add('hidden');
|
||||
document.getElementById('appScreen').classList.add('active');
|
||||
loginProfile(profile.id);
|
||||
hideLoginError();
|
||||
}
|
||||
|
||||
function doLogout() {
|
||||
if (confirm('Выйти из аккаунта?')) {
|
||||
currentProfileId = null;
|
||||
document.getElementById('appScreen').classList.remove('active');
|
||||
document.getElementById('loginScreen').classList.remove('hidden');
|
||||
document.getElementById('loginUser').value = '';
|
||||
document.getElementById('loginPass').value = '';
|
||||
}
|
||||
}
|
||||
|
||||
function showLoginError(msg) {
|
||||
const el = document.getElementById('loginError');
|
||||
el.textContent = msg; el.style.display = 'block';
|
||||
}
|
||||
function hideLoginError() {
|
||||
document.getElementById('loginError').style.display = 'none';
|
||||
}
|
||||
|
||||
function showRegister() {
|
||||
document.getElementById('loginScreen').classList.add('hidden');
|
||||
document.getElementById('profileScreen').classList.remove('hidden');
|
||||
document.getElementById('loginScreen').classList.add('hidden');
|
||||
renderProfileList();
|
||||
}
|
||||
|
||||
function registerProfile() {
|
||||
const name = document.getElementById('regName').value.trim();
|
||||
const login = document.getElementById('regLogin').value.trim().toLowerCase();
|
||||
const pass = document.getElementById('regPass').value;
|
||||
if (!login) return toast('Придумай логин!');
|
||||
if (!pass || pass.length < 3) return toast('Пароль — минимум 3 символа!');
|
||||
const profiles = LS('profiles') || [];
|
||||
if (profiles.find(p => p.login === login)) return toast('Такой логин уже занят!');
|
||||
if (!name) return toast('Введи ФИО!');
|
||||
const profile = {
|
||||
id: Date.now(),
|
||||
@ -389,14 +456,14 @@ function registerProfile() {
|
||||
rank: document.getElementById('regRank').value.trim(),
|
||||
goal: document.getElementById('regGoal').value.trim(),
|
||||
photo: document.getElementById('regPhotoPreview').src || '',
|
||||
created: new Date().toISOString()
|
||||
login, pass, created: new Date().toISOString()
|
||||
};
|
||||
if (profile.photo === window.location.href) profile.photo = '';
|
||||
const profiles = LS('profiles') || [];
|
||||
profiles.push(profile);
|
||||
SS('profiles', profiles);
|
||||
// Clear form
|
||||
['regName','regSport','regAge','regBirth','regCountry','regClub','regCity','regCoach','regRank','regGoal'].forEach(id => document.getElementById(id).value = '');
|
||||
['regName','regLogin','regPass','regSport','regAge','regBirth','regCountry','regClub','regCity','regCoach','regRank','regGoal'].forEach(id => document.getElementById(id).value = '');
|
||||
document.getElementById('regPhotoPreview').style.display = 'none';
|
||||
loginProfile(profile.id);
|
||||
}
|
||||
@ -459,6 +526,7 @@ function loginProfile(id) {
|
||||
const p = profiles.find(x => x.id === id);
|
||||
if (!p) return;
|
||||
document.getElementById('profileScreen').classList.add('hidden');
|
||||
document.getElementById('loginScreen').classList.add('hidden');
|
||||
document.getElementById('appScreen').classList.add('active');
|
||||
document.getElementById('headerName').textContent = p.name.split(' ')[0];
|
||||
const av = document.getElementById('headerAvatar');
|
||||
@ -473,6 +541,7 @@ function loginProfile(id) {
|
||||
|
||||
function showProfileScreen() {
|
||||
document.getElementById('profileScreen').classList.remove('hidden');
|
||||
document.getElementById('loginScreen').classList.add('hidden');
|
||||
document.getElementById('appScreen').classList.remove('active');
|
||||
renderProfileList();
|
||||
}
|
||||
@ -871,10 +940,9 @@ function renderAll() {
|
||||
(function init() {
|
||||
const profiles = LS('profiles') || [];
|
||||
renderProfileList();
|
||||
if (profiles.length > 0) {
|
||||
// Auto-login last profile
|
||||
loginProfile(profiles[profiles.length - 1].id);
|
||||
}
|
||||
// Show login screen - user must enter password
|
||||
document.getElementById('loginScreen').classList.remove('hidden');
|
||||
document.getElementById('appScreen').classList.remove('active');
|
||||
document.getElementById('diary-date').value = new Date().toISOString().slice(0,10);
|
||||
})();
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user