Очистить устаревший черновик регистрации

This commit is contained in:
AidarKC
2026-11-16 10:59:27 +03:00
parent 1b86bca19a
commit 102feccb2e
7 changed files with 71 additions and 72 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
client.version=1.20.50
client.version=1.20.51
server.version=1.16.26
+2 -8
View File
@@ -5,6 +5,7 @@ import {
authService,
authorizeSession,
clearAuthMessages,
resetRegistrationFlow,
consumeAuthReturnPage,
refreshSessions,
setAuthBusy,
@@ -157,14 +158,7 @@ export function render({ navigate }) {
state.loginDraft.password = '';
state.loginDraft.passwordMode = 'single';
state.loginDraft.passwordWords = emptyPasswordWords();
state.registrationDraft.flowType = '';
state.registrationDraft.password = '';
state.registrationDraft.passwordMode = 'single';
state.registrationDraft.passwordWords = emptyPasswordWords();
state.registrationDraft.storagePwd = '';
state.registrationDraft.sessionId = '';
state.registrationDraft.pendingKeyBundle = null;
state.registrationDraft.pendingSessionMaterial = null;
resetRegistrationFlow();
await refreshSessions();
setAuthInfo(t('screens.login_password_view.text_010', { value1: result.login }));
+7 -10
View File
@@ -3,7 +3,7 @@ import { createTopBar } from '../components/topbar.js';
import { createVisiblePasswordField } from '../components/visible-password-field.js';
import { confirmPasswordBoundarySpaces } from '../services/password-boundary-warning.js';
import { createRegistrationStepper } from '../components/registration-stepper.js';
import { authService, clearAuthMessages, state } from '../state.js';
import { authService, clearAuthMessages, clearRegistrationDraft, state } from '../state.js';
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';
@@ -118,11 +118,7 @@ export function render({ navigate }) {
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 = '';
state.registrationPayment.balanceSOL = '0.0000';
draft.preGeneratedKeyBundle = null;
draft.challengeId = '';
draft.challengeExpiresAtMs = 0;
clearRegistrationDraft({ preserveFlowType: true });
}
draft.login = login;
draft.namespaceFeeLamports = String(available.registrationFeeLamports ?? ns.registrationFeeLamports ?? 0);
@@ -184,10 +180,11 @@ export function render({ navigate }) {
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 = '';
state.registrationPayment.balanceSOL = '0.0000';
draft.challengeId = '';
draft.challengeExpiresAtMs = 0;
clearRegistrationDraft({
preserveFlowType: true,
preserveLogin: true,
preserveNamespace: true,
});
}
const revision = inputRevision;
const thisRequest = ++requestId;
+4 -10
View File
@@ -1,10 +1,13 @@
import { t } from '../i18n/index.js';
import { createTopBar } from '../components/topbar.js';
import { state } from '../state.js';
import { resetRegistrationFlow, state } from '../state.js';
export const pageMeta = { id: 'registration-choice-view', get title() { return t('screens.registration_choice_view.text_001'); }, showAppChrome: false };
export function render({ navigate }) {
// Экран выбора начинает новую регистрацию. Старый незавершённый черновик
// нельзя переносить в новый сценарий, особенно после неудачной попытки.
resetRegistrationFlow();
const screen = document.createElement('section');
screen.className = 'stack registration-screen signup-choice';
const title = document.createElement('h1');
@@ -45,15 +48,6 @@ export function render({ navigate }) {
action.textContent = button;
action.addEventListener('click', () => {
const draft = state.registrationDraft;
if (draft.flowType !== type) {
// При смене namespace старые ключи/коды больше не соответствуют выбранному аккаунту.
draft.login = '';
draft.password = '';
draft.preGeneratedKeyBundle = null;
draft.challengeId = '';
draft.challengeExpiresAtMs = 0;
draft.email = '';
}
draft.flowType = type;
draft.uiStep = 1;
navigate('register-view');
+3 -16
View File
@@ -140,22 +140,9 @@ export async function completeRegistrationLogin({ navigate, keyBundle }) {
state.loginDraft.passwordMode = 'single';
state.loginDraft.passwordWords = EMPTY_PASSWORD_WORDS.slice();
state.registrationSuccess = { flowType: state.registrationDraft.flowType, login: resumedLogin };
state.registrationDraft.flowType = '';
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 = '';
state.registrationDraft.sessionId = '';
state.registrationDraft.pendingKeyBundle = null;
state.registrationDraft.pendingSessionMaterial = null;
state.registrationDraft.preGeneratedKeyBundle = null;
state.registrationPayment.walletAddress = '';
state.registrationPayment.balanceSOL = '0.0000';
const completedFlowType = state.registrationDraft.flowType;
resetRegistrationFlow();
state.registrationSuccess = { flowType: completedFlowType, login: resumedLogin };
try {
await refreshSessions();
+51 -27
View File
@@ -29,6 +29,31 @@ const INVALID_SESSION_CODES = new Set([
'SESSION_OF_ANOTHER_USER',
]);
function createEmptyRegistrationDraft() {
return {
uiStep: 1,
flowType: '',
namespaceFeeLamports: '',
namespaceServerLogin: '',
email: '',
challengeId: '',
challengeExpiresAtMs: 0,
dataItemId: '',
login: '',
password: '',
passwordMode: 'single',
passwordWords: emptyPasswordWords(),
passwordWordsLinked: false,
usePromoCode: false,
promoCode: '',
sessionId: '',
storagePwd: '',
pendingKeyBundle: null,
pendingSessionMaterial: null,
preGeneratedKeyBundle: null,
};
}
function isLocalPreviewHost() {
const host = String(window.location.hostname || '').toLowerCase();
return host === 'localhost' || host === '127.0.0.1' || host === '::1';
@@ -458,28 +483,7 @@ function createInitialState({ withStoredSession = true } = {}) {
tools: normalizeToolsSettings(storedEntrySettings?.tools),
},
registrationSuccess: null,
registrationDraft: {
uiStep: 1,
flowType: '',
namespaceFeeLamports: '',
namespaceServerLogin: '',
email: '',
challengeId: '',
challengeExpiresAtMs: 0,
dataItemId: '',
login: '',
password: '',
passwordMode: 'single',
passwordWords: emptyPasswordWords(),
passwordWordsLinked: false,
usePromoCode: false,
promoCode: '',
sessionId: '',
storagePwd: '',
pendingKeyBundle: null,
pendingSessionMaterial: null,
preGeneratedKeyBundle: null,
},
registrationDraft: createEmptyRegistrationDraft(),
registrationHelp: {
selectedTopic: 'keys-storage',
},
@@ -1200,11 +1204,31 @@ export async function refreshSessions() {
}
export function resetRegistrationFlow() {
const next = createInitialState();
state.registrationDraft = next.registrationDraft;
state.registrationSuccess = next.registrationSuccess;
state.registrationHelp = next.registrationHelp;
state.registrationPayment = next.registrationPayment;
clearRegistrationDraft();
state.registrationSuccess = null;
state.registrationHelp = { selectedTopic: 'keys-storage' };
}
/**
* Очищает временные данные регистрации, не затрагивая сохранённые профили и
* ключи уже авторизованных пользователей. При смене логина/пароля старые
* challenge, dataItemId и производные ключи больше не должны переиспользоваться.
*/
export function clearRegistrationDraft({
preserveFlowType = false,
preserveLogin = false,
preserveNamespace = false,
} = {}) {
const draft = state.registrationDraft;
const preserved = {
flowType: preserveFlowType ? draft.flowType : '',
login: preserveLogin ? draft.login : '',
namespaceFeeLamports: preserveNamespace ? draft.namespaceFeeLamports : '',
namespaceServerLogin: preserveNamespace ? draft.namespaceServerLogin : '',
};
Object.assign(draft, createEmptyRegistrationDraft(), preserved);
state.registrationPayment.walletAddress = '';
state.registrationPayment.balanceSOL = '0.0000';
}
function resetStateForSignedOut() {
@@ -83,6 +83,9 @@ async function simulateCompletion({ headerFails = false } = {}) {
authorizeSession: ({ login }) => calls.push(['authorized', login]),
refreshSessions: async () => calls.push(['refreshed']),
setAuthInfo: () => calls.push(['info']),
resetRegistrationFlow: () => {
state.registrationDraft.password = '';
},
console: { warn: (...args) => calls.push(['warning', ...args]) },
};
const func = vm.runInNewContext(`async function completeRegistrationLogin${finish}\ncompleteRegistrationLogin`, context);