UI: доработка регистрации и документации

This commit is contained in:
AidarKC
2026-07-15 16:16:24 +04:00
parent 118be418b5
commit 24cca1f1c6
14 changed files with 192 additions and 104 deletions
+144 -94
View File
@@ -14,7 +14,6 @@ import {
PASSWORD_WORDS_COUNT,
} from '../services/password-words.js';
import { sha256Text } from '../services/crypto-utils.js';
import { openRegistrationFaq } from './registration-faq-view.js';
import { defaultServerHttp } from '../deploy-config.js';
export const pageMeta = { id: 'register-view', title: 'Зарегистрироваться', showAppChrome: false };
@@ -89,6 +88,24 @@ function createWordsLayout({ words, onInput }) {
return { section, inputs, preview };
}
function makePasswordToggleIcons() {
return {
eye: `
<svg class="key-toggle-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M2.4 12s3.6-6.5 9.6-6.5S21.6 12 21.6 12s-3.6 6.5-9.6 6.5S2.4 12 2.4 12Z" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>
<circle cx="12" cy="12" r="2.9" fill="none" stroke="currentColor" stroke-width="1.8"/>
</svg>
`,
eyeOff: `
<svg class="key-toggle-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M3 4l18 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
<path d="M2.4 12s3.6-6.5 9.6-6.5c2.4 0 4.5.8 6.1 1.9" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>
<path d="M21.6 12s-3.6 6.5-9.6 6.5c-2.4 0-4.5-.8-6.1-1.9" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>
</svg>
`,
};
}
export function render({ navigate }) {
const screen = document.createElement('section');
screen.className = 'stack';
@@ -100,7 +117,10 @@ export function render({ navigate }) {
let passwordMode = String(state.registrationDraft.passwordMode || 'single') === 'words' ? 'words' : 'single';
let passwordWords = normalizePasswordWords(state.registrationDraft.passwordWords);
let passwordWordsLinked = Boolean(state.registrationDraft.passwordWordsLinked);
let usePromoCode = Boolean(state.registrationDraft.usePromoCode);
let loginCheckTimer = 0;
let loginCheckRunId = 0;
const loginInput = document.createElement('input');
loginInput.className = 'input';
@@ -119,9 +139,22 @@ export function render({ navigate }) {
passwordInput.autocapitalize = 'off';
passwordInput.spellcheck = false;
passwordInput.maxLength = PASSWORD_MAX_LENGTH;
passwordInput.value = passwordMode === 'single' ? state.registrationDraft.password : '';
passwordInput.value = String(state.registrationDraft.password || '');
passwordInput.placeholder = 'Введите пароль';
const passwordIcons = makePasswordToggleIcons();
const passwordToggleButton = document.createElement('button');
passwordToggleButton.className = 'icon-btn key-toggle-btn registration-password-toggle';
passwordToggleButton.type = 'button';
passwordToggleButton.setAttribute('aria-label', 'Показать пароль');
passwordToggleButton.setAttribute('title', 'Показать пароль');
passwordToggleButton.innerHTML = passwordIcons.eyeOff;
const passwordInputRow = document.createElement('div');
passwordInputRow.className = 'inline-input-row';
passwordInputRow.append(passwordInput, passwordToggleButton);
const {
section: wordsSection,
inputs: wordInputs,
@@ -130,6 +163,7 @@ export function render({ navigate }) {
words: passwordWords,
onInput: (index, value) => {
passwordWords[index] = value;
passwordWordsLinked = true;
syncDraftState();
updateWordsPreview();
},
@@ -182,8 +216,8 @@ export function render({ navigate }) {
promoField.append(promoFieldLabel, promoInput, promoHint);
const statusText = document.createElement('p');
statusText.className = 'meta-muted';
statusText.textContent = 'Проверка логина: не выполнена';
statusText.className = 'status-line';
statusText.style.display = 'none';
const serverNotice = document.createElement('div');
serverNotice.className = 'card stack';
@@ -192,25 +226,6 @@ export function render({ navigate }) {
<p class="meta-muted">При регистрации адресом вашего первого сервера будет: <strong>${state.entrySettings.shineServerHttp || defaultServerHttp}</strong>.</p>
`;
const faqCard = document.createElement('div');
faqCard.className = 'card stack registration-faq-card';
const faqTitle = document.createElement('p');
faqTitle.className = 'field-label';
faqTitle.textContent = 'Частые вопросы перед регистрацией';
const faqText = document.createElement('p');
faqText.className = 'meta-muted';
faqText.textContent = 'Если хотите подробнее понять схему деривации, ключи, первый сервер и формат 12 слов, откройте отдельный экран с вопросами.';
const faqButton = document.createElement('button');
faqButton.className = 'ghost-btn';
faqButton.type = 'button';
faqButton.textContent = 'Частые вопросы';
faqButton.addEventListener('click', () => openRegistrationFaq(navigate, 'key-derivation'));
faqCard.append(faqTitle, faqText, faqButton);
const formError = document.createElement('p');
formError.className = 'status-line is-unavailable';
formError.style.display = 'none';
@@ -253,11 +268,46 @@ export function render({ navigate }) {
passwordLengthText.textContent = text;
}
function setStatusMessage(message, kind = '') {
statusText.textContent = message;
statusText.className = kind ? `status-line ${kind}` : 'status-line';
statusText.style.display = message ? '' : 'none';
}
function resetLoginCheckState() {
lastCheckedLogin = '';
lastCheckedFree = false;
lastCheckedClassName = '';
loginCheckRunId += 1;
if (loginCheckTimer) {
window.clearTimeout(loginCheckTimer);
loginCheckTimer = 0;
}
}
function scheduleAvailabilityCheck() {
resetLoginCheckState();
setStatusMessage('');
if (!loginInput.value.trim()) return;
loginCheckTimer = window.setTimeout(() => {
loginCheckTimer = 0;
runAvailabilityCheck({ automatic: true }).catch(() => {});
}, 1500);
}
function togglePasswordVisibility() {
const reveal = passwordInput.type === 'password';
passwordInput.type = reveal ? 'text' : 'password';
passwordToggleButton.innerHTML = reveal ? passwordIcons.eye : passwordIcons.eyeOff;
passwordToggleButton.setAttribute('aria-label', reveal ? 'Скрыть пароль' : 'Показать пароль');
passwordToggleButton.setAttribute('title', reveal ? 'Скрыть пароль' : 'Показать пароль');
}
function updatePasswordModeVisibility() {
const wordsMode = passwordMode === 'words';
wordsSection.style.display = wordsMode ? 'grid' : 'none';
if (passwordField) passwordField.style.display = wordsMode ? 'none' : 'grid';
passwordInput.style.display = wordsMode ? 'none' : '';
passwordInputRow.style.display = wordsMode ? 'grid' : 'none';
updateWordsPreview();
}
@@ -265,6 +315,7 @@ export function render({ navigate }) {
state.registrationDraft.login = String(loginInput.value.trim());
state.registrationDraft.passwordMode = passwordMode;
state.registrationDraft.passwordWords = normalizePasswordWords(passwordWords);
state.registrationDraft.passwordWordsLinked = passwordWordsLinked;
state.registrationDraft.password = getCurrentPassword();
state.registrationDraft.usePromoCode = usePromoCode;
state.registrationDraft.promoCode = String(promoInput.value || '').trim();
@@ -274,26 +325,25 @@ export function render({ navigate }) {
promoField.style.display = usePromoCode ? 'grid' : 'none';
}
async function runAvailabilityCheck() {
async function runAvailabilityCheck({ automatic = false } = {}) {
const runId = ++loginCheckRunId;
const login = loginInput.value.trim();
const promoCode = String(promoInput.value || '').trim();
if (!login) {
statusText.textContent = 'Введите логин';
setStatusMessage(automatic ? '' : 'Введите логин');
formError.style.display = 'none';
return false;
}
const normalizedLogin = normalizeLoginForTemporaryUiGuard(login);
if (!normalizedLogin) {
statusText.textContent = 'Логин содержит недопустимые символы или имеет неверную длину ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Логин содержит недопустимые символы или имеет неверную длину ❌', 'is-unavailable');
formError.style.display = 'none';
return false;
}
if (normalizedLogin.length < TEMP_ABSOLUTE_MIN_LOGIN_LEN) {
statusText.textContent = `Логин должен быть не короче ${TEMP_ABSOLUTE_MIN_LOGIN_LEN} символов ❌`;
statusText.className = 'status-line is-unavailable';
setStatusMessage(`Логин должен быть не короче ${TEMP_ABSOLUTE_MIN_LOGIN_LEN} символов ❌`, 'is-unavailable');
formError.style.display = 'none';
return false;
}
@@ -302,44 +352,35 @@ export function render({ navigate }) {
let promoAccepted = false;
if (usePromoCode) {
if (!promoCode) {
statusText.textContent = 'Введите промокод ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Введите промокод ❌', 'is-unavailable');
formError.style.display = 'none';
return false;
}
promoAccepted = await isTemporaryPromoAccepted(promoCode);
if (!promoAccepted) {
statusText.textContent = 'Неверный промокод ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Неверный промокод ❌', 'is-unavailable');
formError.style.display = 'none';
return false;
}
} else if (wantsShortLogin) {
statusText.textContent = `Логины короче ${TEMP_MIN_LOGIN_WITHOUT_PROMO} символов временно доступны только по специальному коду ❌`;
statusText.className = 'status-line is-unavailable';
setStatusMessage(`Логины короче ${TEMP_MIN_LOGIN_WITHOUT_PROMO} символов временно доступны только по специальному коду ❌`, 'is-unavailable');
formError.style.display = 'none';
return false;
}
if (login === lastCheckedLogin) {
if (!lastCheckedFree) {
statusText.textContent = 'Логин уже занят ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Логин уже занят ❌', 'is-unavailable');
} else if (lastCheckedClassName === 'promo') {
statusText.textContent = 'Логин свободен ✅ Временный код принят';
statusText.className = 'status-line is-available';
setStatusMessage('Логин свободен ✅ Временный код принят', 'is-available');
} else if (lastCheckedClassName === 'free') {
statusText.textContent = 'Логин свободен ✅';
statusText.className = 'status-line is-available';
setStatusMessage('Логин свободен ✅', 'is-available');
} else if (lastCheckedClassName === 'premium') {
statusText.textContent = 'Логин свободен, но это премиум-логин (покупка через DAO) ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Логин свободен, но это премиум-логин (покупка через DAO) ❌', 'is-unavailable');
} else if (lastCheckedClassName === 'company') {
statusText.textContent = 'Логин свободен, но относится к компании/бренду (отдельное согласование) ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Логин свободен, но относится к компании/бренду (отдельное согласование) ❌', 'is-unavailable');
} else {
statusText.textContent = 'Логин нельзя использовать для обычной регистрации ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Логин нельзя использовать для обычной регистрации ❌', 'is-unavailable');
}
formError.style.display = 'none';
return lastCheckedFree && (lastCheckedClassName === 'free' || lastCheckedClassName === 'promo');
@@ -347,11 +388,13 @@ export function render({ navigate }) {
checkButton.disabled = true;
checkButton.textContent = 'Проверка...';
if (automatic) setStatusMessage('Проверяем логин...');
try {
const check = await checkLoginExistsOnSolana({
login,
solanaEndpoint: state.entrySettings.solanaServer,
});
if (runId !== loginCheckRunId) return false;
const isFree = !check.exists;
let className = '';
let precheckWarning = '';
@@ -375,48 +418,55 @@ export function render({ navigate }) {
lastCheckedFree = isFree;
lastCheckedClassName = className;
if (!isFree) {
statusText.textContent = 'Логин уже занят ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Логин уже занят ❌', 'is-unavailable');
} else if (className === 'promo') {
statusText.textContent = 'Логин свободен ✅ Временный код принят';
statusText.className = 'status-line is-available';
setStatusMessage('Логин свободен ✅ Временный код принят', 'is-available');
} else if (className === 'free') {
statusText.textContent = precheckWarning
? `Логин свободен ✅ (предпроверка Solana недоступна: ${precheckWarning})`
: 'Логин свободен ✅';
statusText.className = 'status-line is-available';
setStatusMessage(
precheckWarning
? `Логин свободен ✅ (предпроверка Solana недоступна: ${precheckWarning})`
: 'Логин свободен ✅',
'is-available',
);
} else if (className === 'premium') {
statusText.textContent = 'Логин свободен, но это премиум-логин (покупка через DAO) ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Логин свободен, но это премиум-логин (покупка через DAO) ❌', 'is-unavailable');
} else if (className === 'company') {
statusText.textContent = 'Логин свободен, но относится к компании/бренду (отдельное согласование) ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Логин свободен, но относится к компании/бренду (отдельное согласование) ❌', 'is-unavailable');
} else {
statusText.textContent = 'Логин нельзя использовать для обычной регистрации ❌';
statusText.className = 'status-line is-unavailable';
setStatusMessage('Логин нельзя использовать для обычной регистрации ❌', 'is-unavailable');
}
formError.style.display = 'none';
return isFree && (className === 'free' || className === 'promo');
} catch (error) {
if (runId !== loginCheckRunId) return false;
const base = toUserMessage(error, 'Не удалось проверить логин');
const details = formatSolanaErrorDetails(error);
statusText.textContent = `${base}. Детали: ${details}`;
statusText.className = 'status-line is-unavailable';
setStatusMessage(`${base}. Детали: ${details}`, 'is-unavailable');
return false;
} finally {
checkButton.disabled = false;
checkButton.textContent = 'Проверить логин';
if (runId === loginCheckRunId) {
checkButton.disabled = false;
checkButton.textContent = 'Проверить логин';
}
}
}
checkButton.addEventListener('click', runAvailabilityCheck);
checkButton.addEventListener('click', () => runAvailabilityCheck());
passwordToggleButton.addEventListener('click', togglePasswordVisibility);
loginInput.addEventListener('input', () => {
syncDraftState();
lastCheckedLogin = '';
scheduleAvailabilityCheck();
});
passwordInput.addEventListener('input', () => {
if (passwordWordsLinked && String(passwordInput.value || '') !== composePasswordFromWords(passwordWords)) {
passwordWords = emptyPasswordWords();
passwordWordsLinked = false;
wordInputs.forEach((input) => {
input.value = '';
});
}
syncDraftState();
updateWordsPreview();
});
@@ -425,13 +475,16 @@ export function render({ navigate }) {
const nextMode = passwordModeCheckbox.checked ? 'words' : 'single';
if (nextMode === passwordMode) return;
if (nextMode === 'words') {
passwordWords = emptyPasswordWords();
wordInputs.forEach((input) => {
input.value = '';
});
passwordInput.value = '';
if (!passwordWordsLinked) {
passwordWords = emptyPasswordWords();
wordInputs.forEach((input) => {
input.value = '';
});
passwordInput.value = '';
}
} else {
passwordInput.value = composePasswordFromWords(passwordWords);
passwordWordsLinked = true;
}
passwordMode = nextMode;
updatePasswordModeVisibility();
@@ -441,25 +494,21 @@ export function render({ navigate }) {
promoCheckbox.addEventListener('change', () => {
usePromoCode = promoCheckbox.checked;
lastCheckedLogin = '';
lastCheckedFree = false;
lastCheckedClassName = '';
resetLoginCheckState();
updatePromoVisibility();
syncDraftState();
if (usePromoCode) {
statusText.textContent = 'Временный код включён: для логинов 5-7 символов будет локальная проверка';
statusText.className = 'status-line is-available';
setStatusMessage('Временный код включён: для логинов 5-7 символов будет локальная проверка', 'is-available');
} else {
statusText.textContent = 'Проверка логина: не выполнена';
statusText.className = 'meta-muted';
setStatusMessage('');
scheduleAvailabilityCheck();
}
});
promoInput.addEventListener('input', () => {
lastCheckedLogin = '';
lastCheckedFree = false;
lastCheckedClassName = '';
resetLoginCheckState();
syncDraftState();
if (usePromoCode) scheduleAvailabilityCheck();
});
nextButton.addEventListener('click', async () => {
@@ -493,6 +542,7 @@ export function render({ navigate }) {
state.registrationDraft.password = nextPassword;
state.registrationDraft.passwordMode = passwordMode;
state.registrationDraft.passwordWords = normalizePasswordWords(passwordWords);
state.registrationDraft.passwordWordsLinked = passwordWordsLinked;
state.registrationDraft.usePromoCode = usePromoCode;
state.registrationDraft.promoCode = promoCode;
if (credsChanged) {
@@ -504,16 +554,18 @@ export function render({ navigate }) {
function renderInputStage() {
serverNotice.style.display = '';
faqCard.style.display = '';
form.innerHTML = `
<label class="stack"><span class="field-label">Логин</span></label>
<label class="stack registration-password-single"><span class="field-label">Пароль</span></label>
`;
const loginField = form.children[0];
passwordField = form.children[1];
form.innerHTML = '';
const loginField = document.createElement('label');
loginField.className = 'stack';
loginField.innerHTML = '<span class="field-label">Логин</span>';
const passwordLabel = document.createElement('label');
passwordLabel.className = 'stack registration-password-single';
passwordLabel.innerHTML = '<span class="field-label">Пароль</span>';
form.append(loginField, statusText, checkButton, passwordLabel);
passwordField = passwordLabel;
loginField.append(loginInput);
passwordField.append(passwordInput);
form.append(passwordModeToggle, promoToggle, promoField, passwordLengthText, wordsSection, statusText, checkButton, formError);
passwordField.append(passwordInputRow);
form.append(passwordModeToggle, promoToggle, promoField, passwordLengthText, wordsSection, formError);
actions.innerHTML = '';
actions.append(backButton, nextButton);
updatePasswordModeVisibility();
@@ -523,7 +575,6 @@ export function render({ navigate }) {
async function startGenerationStage() {
serverNotice.style.display = 'none';
faqCard.style.display = 'none';
const runId = ++generationRunId;
form.innerHTML = '';
@@ -630,7 +681,6 @@ export function render({ navigate }) {
}),
form,
serverNotice,
faqCard,
actions,
);
@@ -155,6 +155,7 @@ export function render({ navigate }) {
state.registrationDraft.password = '';
state.registrationDraft.passwordMode = 'single';
state.registrationDraft.passwordWords = EMPTY_PASSWORD_WORDS.slice();
state.registrationDraft.passwordWordsLinked = false;
state.registrationDraft.usePromoCode = false;
state.registrationDraft.promoCode = '';
state.registrationDraft.storagePwd = '';
@@ -82,6 +82,7 @@ async function completeRegistrationLogin({ navigate, keyBundle }) {
state.registrationDraft.password = '';
state.registrationDraft.passwordMode = 'single';
state.registrationDraft.passwordWords = EMPTY_PASSWORD_WORDS.slice();
state.registrationDraft.passwordWordsLinked = false;
state.registrationDraft.usePromoCode = false;
state.registrationDraft.promoCode = '';
state.registrationDraft.storagePwd = '';