SHA256
Локализовать интерфейс SHiNE на русский и английский
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { t, th } from '../i18n/index.js';
|
||||
import { createTopBar } from '../components/topbar.js';
|
||||
import { createVisiblePasswordField } from '../components/visible-password-field.js';
|
||||
import { confirmPasswordBoundarySpaces } from '../services/password-boundary-warning.js';
|
||||
@@ -7,7 +8,7 @@ import { PASSWORD_MAX_LENGTH } from '../services/password-words.js';
|
||||
import { getRegistrationNamespaces, checkRegistrationLogin } from '../services/registration-v2-api.js';
|
||||
import { normalizeFullLogin } from '../services/shine-namespace-service.js';
|
||||
|
||||
export const pageMeta = { id: 'register-view', title: 'Регистрация', showAppChrome: false };
|
||||
export const pageMeta = { id: 'register-view', get title() { return t('screens.register_view.text_001'); }, showAppChrome: false };
|
||||
|
||||
export function render({ navigate }) {
|
||||
clearAuthMessages();
|
||||
@@ -16,7 +17,7 @@ export function render({ navigate }) {
|
||||
screen.className = 'stack registration-screen signup-wizard';
|
||||
const body = document.createElement('div');
|
||||
body.className = 'card stack registration-form signup-wizard__body';
|
||||
const header = createTopBar({ title: 'Регистрация в Сиянии', back: { label: '←', onClick: goBack } });
|
||||
const header = createTopBar({ title: t('screens.register_view.text_002'), back: { label: '←', onClick: goBack } });
|
||||
screen.append(header, body);
|
||||
|
||||
let namespaces = [];
|
||||
@@ -30,7 +31,7 @@ export function render({ navigate }) {
|
||||
function confirmFundedWalletChange() {
|
||||
const balance = Number(state.registrationPayment?.balanceSOL || 0);
|
||||
if (balance <= 0) return true;
|
||||
return window.confirm('Внимание: кошелёк уже пополнен. Изменение логина или пароля создаст другой кошелёк! Средства останутся на старом адресе, и для доступа к ним потребуется прежний пароль. Продолжить?');
|
||||
return window.confirm(t('screens.register_view.text_039'));
|
||||
}
|
||||
function goBack() {
|
||||
if (Number(draft.uiStep) === 2) {
|
||||
@@ -63,15 +64,15 @@ export function render({ navigate }) {
|
||||
function showLogin() {
|
||||
draft.uiStep = 1;
|
||||
body.replaceChildren(createRegistrationStepper(1));
|
||||
const [heading, description] = title('Введите логин', 'Это имя навсегда сохранится и будет отображаться именно так, как вы выберете сейчас. Позже изменить его нельзя.');
|
||||
const [heading, description] = title(t('screens.register_view.text_014'), t('screens.register_view.text_015'));
|
||||
const label = document.createElement('label');
|
||||
label.className = 'stack';
|
||||
const labelText = document.createElement('span');
|
||||
labelText.className = 'field-label';
|
||||
labelText.textContent = 'Ваш логин';
|
||||
labelText.textContent = t('screens.register_view.text_003');
|
||||
const input = document.createElement('input');
|
||||
input.className = 'input';
|
||||
input.placeholder = 'Например, Alice';
|
||||
input.placeholder = t('screens.register_view.text_004');
|
||||
input.autocomplete = 'off';
|
||||
input.autocapitalize = 'off';
|
||||
input.spellcheck = false;
|
||||
@@ -81,40 +82,40 @@ export function render({ navigate }) {
|
||||
fullLogin.className = 'signup-full-login';
|
||||
const caseInfo = document.createElement('p');
|
||||
caseInfo.className = 'meta-muted';
|
||||
caseInfo.textContent = 'Регистр сохраняется: Alice и alice при проверке считаются одним логином, но отображаться будет выбранное написание всегда.';
|
||||
caseInfo.textContent = t('screens.register_view.text_005');
|
||||
const status = statusLine();
|
||||
const next = document.createElement('button');
|
||||
next.className = 'primary-btn signup-next';
|
||||
next.textContent = 'Продолжить';
|
||||
next.textContent = t('screens.register_view.text_006');
|
||||
next.type = 'button';
|
||||
next.disabled = isLoading;
|
||||
function updateFull() {
|
||||
const ns = selectedNamespace();
|
||||
fullLogin.textContent = ns ? `${input.value.trim() || 'ВашЛогин'}@${ns.name}` : 'Пока нет доступного пространства имён';
|
||||
fullLogin.textContent = ns ? `${input.value.trim() || t('screens.register_view.text_021')}@${ns.name}` : t('screens.register_view.text_018');
|
||||
status.textContent = fetchError;
|
||||
next.disabled = isLoading || !ns;
|
||||
}
|
||||
input.addEventListener('input', () => { inputRevision++; localDraft = input.value; updateFull(); });
|
||||
next.addEventListener('click', async () => {
|
||||
const ns = selectedNamespace();
|
||||
if (!ns) { status.textContent = 'Пространство имён пока недоступно'; return; }
|
||||
if (!ns) { status.textContent = t('screens.register_view.text_007'); return; }
|
||||
let login;
|
||||
try {
|
||||
const local = input.value.trim();
|
||||
if (local.length < Number(ns.minLocalLength)) throw new Error(`Минимальная длина логина: ${ns.minLocalLength} символов.`);
|
||||
if (local.length < Number(ns.minLocalLength)) throw new Error(t('screens.register_view.text_030', { value1: ns.minLocalLength }));
|
||||
login = normalizeFullLogin(`${local}@${ns.name}`);
|
||||
} catch (error) { status.textContent = error.message; return; }
|
||||
const revision = inputRevision;
|
||||
const thisRequest = ++requestId;
|
||||
next.disabled = true;
|
||||
status.textContent = 'Проверяем доступность логина…';
|
||||
status.textContent = t('screens.register_view.text_008');
|
||||
try {
|
||||
const available = await checkRegistrationLogin(login);
|
||||
if (!screen.isConnected || thisRequest !== requestId) return;
|
||||
if (revision !== inputRevision) throw new Error('Логин изменился. Нажмите «Продолжить» ещё раз.');
|
||||
if (!available.loginAvailable) throw new Error('Такой логин уже занят. Попробуйте другой.');
|
||||
if (Number(available.namespaceType) !== Number(ns.type)) throw new Error('Тип регистрации изменился. Вернитесь к выбору аккаунта.');
|
||||
if (Number(available.currencyCode ?? 1) !== 1 || Number(ns.currencyCode ?? 1) !== 1) throw new Error('Валюта регистрации пока не поддерживается.');
|
||||
if (revision !== inputRevision) throw new Error(t('screens.register_view.text_022'));
|
||||
if (!available.loginAvailable) throw new Error(t('screens.register_view.text_023'));
|
||||
if (Number(available.namespaceType) !== Number(ns.type)) throw new Error(t('screens.register_view.text_024'));
|
||||
if (Number(available.currencyCode ?? 1) !== 1 || Number(ns.currencyCode ?? 1) !== 1) throw new Error(t('screens.register_view.text_025'));
|
||||
if (draft.login !== login) {
|
||||
if (!confirmFundedWalletChange()) return;
|
||||
state.registrationPayment.walletAddress = '';
|
||||
@@ -129,7 +130,7 @@ export function render({ navigate }) {
|
||||
draft.uiStep = 2;
|
||||
showPassword();
|
||||
} catch (error) {
|
||||
if (screen.isConnected && thisRequest === requestId) status.textContent = error.message || 'Ошибка проверки логина.';
|
||||
if (screen.isConnected && thisRequest === requestId) status.textContent = error.message || t('screens.register_view.text_026');
|
||||
} finally {
|
||||
if (screen.isConnected && thisRequest === requestId) next.disabled = false;
|
||||
}
|
||||
@@ -140,47 +141,47 @@ export function render({ navigate }) {
|
||||
function showPassword() {
|
||||
draft.uiStep = 2;
|
||||
body.replaceChildren(createRegistrationStepper(2));
|
||||
const [heading, description] = title('Придумайте пароль', 'На вашем устройстве из логина и пароля создаются криптографические ключи доступа. Приватные ключи не хранятся на сервере.');
|
||||
const [heading, description] = title(t('screens.register_view.text_016'), t('screens.register_view.text_017'));
|
||||
const label = document.createElement('label');
|
||||
label.className = 'stack';
|
||||
const labelText = document.createElement('span');
|
||||
labelText.className = 'field-label';
|
||||
labelText.textContent = `Пароль (от 1 до ${PASSWORD_MAX_LENGTH} символов)`;
|
||||
labelText.textContent = t('screens.register_view.text_031', { value1: PASSWORD_MAX_LENGTH });
|
||||
const input = document.createElement('input');
|
||||
input.className = 'input';
|
||||
input.type = 'text';
|
||||
input.autocomplete = 'new-password';
|
||||
input.maxLength = PASSWORD_MAX_LENGTH;
|
||||
input.placeholder = 'Ваш секретный пароль';
|
||||
input.placeholder = t('screens.register_view.text_009');
|
||||
input.value = draft.password || '';
|
||||
label.append(labelText, createVisiblePasswordField(input));
|
||||
const guidance = document.createElement('div');
|
||||
guidance.className = 'signup-guidance';
|
||||
guidance.innerHTML = `
|
||||
<strong>Лучший пароль — тот, который вы точно помните.</strong>
|
||||
<p>Подойдёт любой непустой пароль. Для надёжности лучше выбрать свою длинную фразу или случайный код. Не используйте известные цитаты и очевидные последовательности.</p>
|
||||
<p>На привычном устройстве обычно не придётся вводить пароль при каждом входе: рабочие ключи сохраняются локально. Для входа с нового устройства пароль — ваш резервный способ доступа.</p>
|
||||
<p class="signup-guidance__warning"><strong>Не теряйте пароль!</strong> Мы не можем восстановить его или ваши ключи. Если доступ к ключам на всех устройствах утрачен, зашифрованная личная переписка может оказаться недоступна.</p>
|
||||
<strong>${th('screens.register_view.text_034')}</strong>
|
||||
<p>${th('screens.register_view.text_035')}</p>
|
||||
<p>${th('screens.register_view.text_036')}</p>
|
||||
<p class="signup-guidance__warning"><strong>${th('screens.register_view.text_037')}</strong> ${th('screens.register_view.text_038')}</p>
|
||||
<p>${flowType === 'free'
|
||||
? 'В бесплатном аккаунте смена пароля недоступна. После перехода на полноценный аккаунт появится возможность его менять.'
|
||||
: 'Для полноценного аккаунта поддерживается смена пароля: необходимые зашифрованные сообщения перешифровываются на вашем устройстве, а не на сервере.'}</p>
|
||||
? t('screens.register_view.text_019')
|
||||
: t('screens.register_view.text_020')}</p>
|
||||
`;
|
||||
const status = statusLine();
|
||||
const next = document.createElement('button');
|
||||
next.className = 'primary-btn signup-next';
|
||||
next.type = 'button';
|
||||
next.textContent = 'Продолжить';
|
||||
next.textContent = t('screens.register_view.text_010');
|
||||
input.addEventListener('input', () => { inputRevision++; status.textContent = ''; });
|
||||
next.addEventListener('click', async () => {
|
||||
const value = input.value;
|
||||
if (value.length < 1 || value.length > PASSWORD_MAX_LENGTH) {
|
||||
status.textContent = `Введите пароль длиной от 1 до ${PASSWORD_MAX_LENGTH} символов.`;
|
||||
status.textContent = t('screens.register_view.text_032', { value1: PASSWORD_MAX_LENGTH });
|
||||
return;
|
||||
}
|
||||
if (!draft.login || !draft.login.includes('@')) { status.textContent = 'Сначала выберите логин.'; return; }
|
||||
if (!draft.login || !draft.login.includes('@')) { status.textContent = t('screens.register_view.text_011'); return; }
|
||||
const warningRevision = inputRevision;
|
||||
if (!await confirmPasswordBoundarySpaces(value) || !screen.isConnected) return;
|
||||
if (warningRevision !== inputRevision || input.value !== value) { status.textContent = 'Пароль изменился. Нажмите «Продолжить» ещё раз.'; return; }
|
||||
if (warningRevision !== inputRevision || input.value !== value) { status.textContent = t('screens.register_view.text_012'); return; }
|
||||
if (draft.password && draft.password !== value && !confirmFundedWalletChange()) return;
|
||||
if (draft.password && draft.password !== value) {
|
||||
state.registrationPayment.walletAddress = '';
|
||||
@@ -191,18 +192,18 @@ export function render({ navigate }) {
|
||||
const revision = inputRevision;
|
||||
const thisRequest = ++requestId;
|
||||
next.disabled = true;
|
||||
status.textContent = 'Генерируем ключи из пароля на этом устройстве…';
|
||||
status.textContent = t('screens.register_view.text_013');
|
||||
try {
|
||||
const changed = draft.password !== value;
|
||||
draft.password = value;
|
||||
if (changed) draft.preGeneratedKeyBundle = null;
|
||||
const bundle = draft.preGeneratedKeyBundle || await authService.derivePasswordKeyBundle(draft.login, value);
|
||||
if (!screen.isConnected || thisRequest !== requestId) return;
|
||||
if (revision !== inputRevision) throw new Error('Пароль изменился. Нажмите «Продолжить» ещё раз.');
|
||||
if (revision !== inputRevision) throw new Error(t('screens.register_view.text_027'));
|
||||
draft.preGeneratedKeyBundle = bundle;
|
||||
navigate(flowType === 'free' ? 'registration-email-view' : 'registration-payment-view');
|
||||
} catch (error) {
|
||||
if (screen.isConnected && thisRequest === requestId) status.textContent = error.message || 'Не удалось создать ключи.';
|
||||
if (screen.isConnected && thisRequest === requestId) status.textContent = error.message || t('screens.register_view.text_028');
|
||||
} finally {
|
||||
if (screen.isConnected && thisRequest === requestId) next.disabled = false;
|
||||
}
|
||||
@@ -220,11 +221,11 @@ export function render({ navigate }) {
|
||||
void getRegistrationNamespaces().then(data => {
|
||||
namespaces = Array.isArray(data.namespaces) ? data.namespaces : [];
|
||||
isLoading = false;
|
||||
if (!selectedNamespace()) fetchError = 'Сервер пока не предоставил пространство имён для выбранного типа регистрации.';
|
||||
if (!selectedNamespace()) fetchError = t('screens.register_view.text_029');
|
||||
if (screen.isConnected && Number(draft.uiStep) === 1) showLogin();
|
||||
}).catch(error => {
|
||||
isLoading = false;
|
||||
fetchError = `Не удалось загрузить пространства имён: ${error.message}`;
|
||||
fetchError = t('screens.register_view.text_033', { value1: error.message });
|
||||
if (screen.isConnected && Number(draft.uiStep) === 1) showLogin();
|
||||
});
|
||||
return screen;
|
||||
|
||||
Reference in New Issue
Block a user