Auth: auto-register on 404 for both FIO and CDN input modes
This commit is contained in:
parent
b5bb8a81d7
commit
f1a4915738
15
index.html
15
index.html
@ -1941,25 +1941,24 @@ const SCHEDULE = [
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: not found — for FIO mode, offer to register
|
// Step 2: not found — auto-register with whatever was typed
|
||||||
if (login.status === 404 && mode === 'fio') {
|
if (login.status === 404) {
|
||||||
submit.textContent = 'Создаю аккаунт...';
|
submit.textContent = 'Создаю аккаунт...';
|
||||||
hint.innerHTML = `Аккаунт <code>${cdn}</code> не найден — создаю новый...`;
|
hint.innerHTML = `Аккаунт <code>${cdn}</code> не найден — создаю новый...`;
|
||||||
const reg = await apiCall('/register', { fio: input.value.trim() });
|
// FIO mode → send fio (backend will generate cdn); CDN mode → send cdn directly
|
||||||
|
const regBody = mode === 'fio'
|
||||||
|
? { fio: input.value.trim() }
|
||||||
|
: { cdn: input.value.trim() };
|
||||||
|
const reg = await apiCall('/register', regBody);
|
||||||
if (reg.ok) {
|
if (reg.ok) {
|
||||||
localStorage.setItem(STORAGE_KEY, reg.data.cdn);
|
localStorage.setItem(STORAGE_KEY, reg.data.cdn);
|
||||||
refreshHeader();
|
refreshHeader();
|
||||||
redirectTo(reg.data.cdn, reg.data.vscode_url);
|
redirectTo(reg.data.cdn, reg.data.vscode_url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// registration failed
|
|
||||||
const msg = reg.data?.detail?.message || reg.data?.detail?.error || `HTTP ${reg.status}`;
|
const msg = reg.data?.detail?.message || reg.data?.detail?.error || `HTTP ${reg.status}`;
|
||||||
hint.textContent = `Не удалось создать: ${msg}`;
|
hint.textContent = `Не удалось создать: ${msg}`;
|
||||||
hint.classList.add('error');
|
hint.classList.add('error');
|
||||||
} else if (login.status === 404) {
|
|
||||||
// CDN mode, no exact match — prompt full name
|
|
||||||
hint.innerHTML = `CDN <code>${cdn}</code> не найден. Введи имя и фамилию для регистрации.`;
|
|
||||||
hint.classList.add('error');
|
|
||||||
} else {
|
} else {
|
||||||
const msg = login.data?.detail?.message || login.data?.detail?.error || `HTTP ${login.status}`;
|
const msg = login.data?.detail?.message || login.data?.detail?.error || `HTTP ${login.status}`;
|
||||||
hint.textContent = `Ошибка: ${msg}`;
|
hint.textContent = `Ошибка: ${msg}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user