SHA256
Улучшить ввод пароля при входе и регистрации
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import { createTopBar } from '../components/topbar.js';
|
||||
import { createVisiblePasswordField } from '../components/visible-password-field.js';
|
||||
import { createVisiblePasswordField, createExpandablePasswordTextarea } from '../components/visible-password-field.js';
|
||||
import { createSecretGenerationOverlay } from '../components/secret-generation-overlay.js';
|
||||
import {
|
||||
authService,
|
||||
authorizeSession,
|
||||
@@ -24,31 +25,6 @@ function setStatus(statusEl, message) {
|
||||
statusEl.style.display = message ? '' : 'none';
|
||||
}
|
||||
|
||||
function createSecretOverlay() {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'secret-generation-overlay';
|
||||
overlay.style.display = 'none';
|
||||
|
||||
const card = document.createElement('div');
|
||||
card.className = 'secret-generation-card stack';
|
||||
|
||||
const spinner = document.createElement('div');
|
||||
spinner.className = 'secret-generation-spinner';
|
||||
spinner.setAttribute('aria-hidden', 'true');
|
||||
|
||||
const title = document.createElement('div');
|
||||
title.className = 'secret-generation-title';
|
||||
title.textContent = t('screens.login_password_view.text_002');
|
||||
|
||||
const progress = document.createElement('div');
|
||||
progress.className = 'secret-generation-progress';
|
||||
progress.textContent = '';
|
||||
|
||||
card.append(spinner, title, progress);
|
||||
overlay.append(card);
|
||||
return { overlay, progress };
|
||||
}
|
||||
|
||||
export function render({ navigate }) {
|
||||
const screen = document.createElement('section');
|
||||
screen.className = 'stack auth-screen auth-screen--lower';
|
||||
@@ -70,9 +46,7 @@ export function render({ navigate }) {
|
||||
const passwordField = document.createElement('label');
|
||||
passwordField.className = 'stack';
|
||||
|
||||
const passwordInput = document.createElement('input');
|
||||
passwordInput.className = 'input';
|
||||
passwordInput.type = 'text';
|
||||
const passwordInput = createExpandablePasswordTextarea();
|
||||
passwordInput.name = 'shine-login-password';
|
||||
passwordInput.autocomplete = 'current-password';
|
||||
passwordInput.autocapitalize = 'off';
|
||||
@@ -96,7 +70,7 @@ export function render({ navigate }) {
|
||||
actions.className = 'auth-footer-actions';
|
||||
actions.append(enterButton);
|
||||
|
||||
const { overlay, progress } = createSecretOverlay();
|
||||
const keyGeneration = createSecretGenerationOverlay();
|
||||
|
||||
const submit = async () => {
|
||||
const currentLogin = String(state.loginDraft.login || '').trim();
|
||||
@@ -131,14 +105,10 @@ export function render({ navigate }) {
|
||||
return;
|
||||
}
|
||||
|
||||
overlay.style.display = 'grid';
|
||||
const keyBundle = await authService.derivePasswordKeyBundle(currentLogin, password, {
|
||||
onProgress: ({ percent }) => {
|
||||
const value = Math.max(0, Math.min(100, Number(percent) || 0));
|
||||
progress.textContent = value > 0 && value < 100 ? `${Math.round(value)}%` : '';
|
||||
},
|
||||
});
|
||||
overlay.style.display = 'none';
|
||||
keyGeneration.show();
|
||||
await new Promise(resolve => setTimeout(resolve, 40));
|
||||
const keyBundle = await authService.derivePasswordKeyBundle(currentLogin, password);
|
||||
keyGeneration.hide();
|
||||
|
||||
enterButton.textContent = t('screens.login_password_view.text_006');
|
||||
const result = await authService.createAuthSession(currentLogin, keyBundle);
|
||||
@@ -156,6 +126,8 @@ export function render({ navigate }) {
|
||||
});
|
||||
state.loginDraft.login = result.login;
|
||||
state.loginDraft.password = '';
|
||||
// Clear the actual textarea as soon as login succeeds, before route change.
|
||||
passwordInput.clearPasswordField();
|
||||
state.loginDraft.passwordMode = 'single';
|
||||
state.loginDraft.passwordWords = emptyPasswordWords();
|
||||
resetRegistrationFlow();
|
||||
@@ -164,7 +136,7 @@ export function render({ navigate }) {
|
||||
setAuthInfo(t('screens.login_password_view.text_010', { value1: result.login }));
|
||||
navigate(consumeAuthReturnPage('profile-view'));
|
||||
} catch (error) {
|
||||
overlay.style.display = 'none';
|
||||
keyGeneration.hide();
|
||||
const message = toUserMessage(error, t('screens.login_password_view.text_008'));
|
||||
setAuthError(message);
|
||||
setStatus(status, message);
|
||||
@@ -178,7 +150,7 @@ export function render({ navigate }) {
|
||||
|
||||
enterButton.addEventListener('click', submit);
|
||||
passwordInput.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Enter') {
|
||||
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
|
||||
event.preventDefault();
|
||||
void submit();
|
||||
}
|
||||
@@ -192,9 +164,9 @@ export function render({ navigate }) {
|
||||
back: { label: '←', onClick: () => navigate('login-view') },
|
||||
}),
|
||||
panel,
|
||||
overlay,
|
||||
keyGeneration.overlay,
|
||||
);
|
||||
|
||||
window.setTimeout(() => passwordInput.focus(), 0);
|
||||
window.setTimeout(() => { passwordInput.resizePasswordField(); passwordInput.focus(); }, 0);
|
||||
return screen;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { t, th } from '../i18n/index.js';
|
||||
import { createTopBar } from '../components/topbar.js';
|
||||
import { createVisiblePasswordField } from '../components/visible-password-field.js';
|
||||
import { createVisiblePasswordField, createExpandablePasswordTextarea } from '../components/visible-password-field.js';
|
||||
import { createSecretGenerationOverlay } from '../components/secret-generation-overlay.js';
|
||||
import { confirmPasswordBoundarySpaces } from '../services/password-boundary-warning.js';
|
||||
import { createRegistrationStepper } from '../components/registration-stepper.js';
|
||||
import { authService, clearAuthMessages, clearRegistrationDraft, state } from '../state.js';
|
||||
@@ -18,7 +19,8 @@ export function render({ navigate }) {
|
||||
const body = document.createElement('div');
|
||||
body.className = 'card stack registration-form signup-wizard__body';
|
||||
const header = createTopBar({ title: t('screens.register_view.text_002'), back: { label: '←', onClick: goBack } });
|
||||
screen.append(header, body);
|
||||
const keyGeneration = createSecretGenerationOverlay();
|
||||
screen.append(header, body, keyGeneration.overlay);
|
||||
|
||||
let namespaces = [];
|
||||
let isLoading = true;
|
||||
@@ -143,14 +145,21 @@ export function render({ navigate }) {
|
||||
const labelText = document.createElement('span');
|
||||
labelText.className = 'field-label';
|
||||
labelText.textContent = t('screens.register_view.text_031', { value1: PASSWORD_MAX_LENGTH });
|
||||
const input = document.createElement('input');
|
||||
input.className = 'input';
|
||||
input.type = 'text';
|
||||
const input = createExpandablePasswordTextarea();
|
||||
input.autocomplete = 'new-password';
|
||||
input.maxLength = PASSWORD_MAX_LENGTH;
|
||||
input.placeholder = t('screens.register_view.text_009');
|
||||
input.value = draft.password || '';
|
||||
label.append(labelText, createVisiblePasswordField(input));
|
||||
// Never repopulate a successfully submitted secret on returning to this step.
|
||||
input.value = '';
|
||||
const passwordCount = document.createElement('span');
|
||||
passwordCount.className = 'password-length-hint';
|
||||
passwordCount.setAttribute('aria-live', 'off');
|
||||
const refreshPasswordCount = () => {
|
||||
passwordCount.textContent = t('screens.register_view.password_counter', { value1: input.value.length, value2: PASSWORD_MAX_LENGTH });
|
||||
};
|
||||
label.append(labelText, createVisiblePasswordField(input), passwordCount);
|
||||
refreshPasswordCount();
|
||||
requestAnimationFrame(() => input.resizePasswordField());
|
||||
const guidance = document.createElement('div');
|
||||
guidance.className = 'signup-guidance';
|
||||
guidance.innerHTML = `
|
||||
@@ -167,7 +176,13 @@ export function render({ navigate }) {
|
||||
next.className = 'primary-btn signup-next';
|
||||
next.type = 'button';
|
||||
next.textContent = t('screens.register_view.text_010');
|
||||
input.addEventListener('input', () => { inputRevision++; status.textContent = ''; });
|
||||
input.addEventListener('input', () => { inputRevision++; status.textContent = ''; refreshPasswordCount(); });
|
||||
input.addEventListener('keydown', event => {
|
||||
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
|
||||
event.preventDefault();
|
||||
next.click();
|
||||
}
|
||||
});
|
||||
next.addEventListener('click', async () => {
|
||||
const value = input.value;
|
||||
if (value.length < 1 || value.length > PASSWORD_MAX_LENGTH) {
|
||||
@@ -188,9 +203,13 @@ export function render({ navigate }) {
|
||||
}
|
||||
const revision = inputRevision;
|
||||
const thisRequest = ++requestId;
|
||||
const needsGeneration = draft.password !== value || !draft.preGeneratedKeyBundle;
|
||||
next.disabled = true;
|
||||
status.textContent = t('screens.register_view.text_013');
|
||||
status.textContent = '';
|
||||
if (needsGeneration) keyGeneration.show();
|
||||
try {
|
||||
// Дать браузеру отрисовать заставку до тяжёлого KDF.
|
||||
if (needsGeneration) await new Promise(resolve => setTimeout(resolve, 40));
|
||||
const changed = draft.password !== value;
|
||||
draft.password = value;
|
||||
if (changed) draft.preGeneratedKeyBundle = null;
|
||||
@@ -198,10 +217,14 @@ export function render({ navigate }) {
|
||||
if (!screen.isConnected || thisRequest !== requestId) return;
|
||||
if (revision !== inputRevision) throw new Error(t('screens.register_view.text_027'));
|
||||
draft.preGeneratedKeyBundle = bundle;
|
||||
// Hide the password before navigation to prevent a visible flash.
|
||||
input.clearPasswordField();
|
||||
refreshPasswordCount();
|
||||
navigate(flowType === 'free' ? 'registration-email-view' : 'registration-payment-view');
|
||||
} catch (error) {
|
||||
if (screen.isConnected && thisRequest === requestId) status.textContent = error.message || t('screens.register_view.text_028');
|
||||
} finally {
|
||||
keyGeneration.hide();
|
||||
if (screen.isConnected && thisRequest === requestId) next.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user