Fix auth username editing in hub panel
This commit is contained in:
1 parent
47dd1f89c1
commit
e96356a422
1 file changed
+29
-7
+29
-7
@@ -6547,6 +6547,7 @@ const backupPublicUrl = document.getElementById('backupPublicUrl');
|
|||||||
const backupRestore = document.getElementById('backupRestore');
|
const backupRestore = document.getElementById('backupRestore');
|
||||||
const backupMsg = document.getElementById('backupMsg');
|
const backupMsg = document.getElementById('backupMsg');
|
||||||
const authForm = document.getElementById('authForm');
|
const authForm = document.getElementById('authForm');
|
||||||
|
const authUsernameField = authForm && authForm.elements ? authForm.elements.namedItem('username') : null;
|
||||||
const authMsg = document.getElementById('authMsg');
|
const authMsg = document.getElementById('authMsg');
|
||||||
const authSummary = document.getElementById('authSummary');
|
const authSummary = document.getElementById('authSummary');
|
||||||
const totpState = document.getElementById('totpState');
|
const totpState = document.getElementById('totpState');
|
||||||
@@ -6575,6 +6576,8 @@ const sshKeyList = document.getElementById('sshKeyList');
|
|||||||
let authHideTimer;
|
let authHideTimer;
|
||||||
let authMeta = null;
|
let authMeta = null;
|
||||||
let authTotpTicket = '';
|
let authTotpTicket = '';
|
||||||
|
let authUsernameDraftDirty = false;
|
||||||
|
let authUsernameServerValue = authUsernameField && 'value' in authUsernameField ? String(authUsernameField.value || '') : '';
|
||||||
function hideOfflineStats() {{
|
function hideOfflineStats() {{
|
||||||
if (!offlineStatsExpanded) return;
|
if (!offlineStatsExpanded) return;
|
||||||
offlineStatsExpanded = false;
|
offlineStatsExpanded = false;
|
||||||
@@ -6588,6 +6591,26 @@ function closeAuthMenu(returnFocus = false) {{
|
|||||||
if (authMenuHeadTitle) authMenuHeadTitle.textContent = '\u0414\u043e\u0441\u0442\u0443\u043f \u043a Hub';
|
if (authMenuHeadTitle) authMenuHeadTitle.textContent = '\u0414\u043e\u0441\u0442\u0443\u043f \u043a Hub';
|
||||||
if (authMenuHeadLead) authMenuHeadLead.hidden = true;
|
if (authMenuHeadLead) authMenuHeadLead.hidden = true;
|
||||||
if (authMenuClose) authMenuClose.textContent = '\u0417\u0430\u043a\u0440\u044b\u0442\u044c';
|
if (authMenuClose) authMenuClose.textContent = '\u0417\u0430\u043a\u0440\u044b\u0442\u044c';
|
||||||
|
function syncAuthUsernameField(force = false) {{
|
||||||
|
if (!authUsernameField || !authMeta || !authMeta.username) return;
|
||||||
|
const serverValue = String(authMeta.username || '');
|
||||||
|
const isEditing = document.activeElement === authUsernameField;
|
||||||
|
if (!force && (isEditing || authUsernameDraftDirty)) {{
|
||||||
|
authUsernameServerValue = serverValue;
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
authUsernameField.value = serverValue;
|
||||||
|
authUsernameServerValue = serverValue;
|
||||||
|
authUsernameDraftDirty = false;
|
||||||
|
}}
|
||||||
|
if (authUsernameField) {{
|
||||||
|
const updateAuthUsernameDraftState = () => {{
|
||||||
|
authUsernameDraftDirty = String(authUsernameField.value || '') !== authUsernameServerValue;
|
||||||
|
}};
|
||||||
|
authUsernameField.addEventListener('input', updateAuthUsernameDraftState);
|
||||||
|
authUsernameField.addEventListener('change', updateAuthUsernameDraftState);
|
||||||
|
authUsernameField.addEventListener('blur', updateAuthUsernameDraftState);
|
||||||
|
}}
|
||||||
function localizeAuthUi() {{
|
function localizeAuthUi() {{
|
||||||
const securityGroupTitle = document.getElementById('securityGroupTitle');
|
const securityGroupTitle = document.getElementById('securityGroupTitle');
|
||||||
const securityGroupLead = document.getElementById('securityGroupLead');
|
const securityGroupLead = document.getElementById('securityGroupLead');
|
||||||
@@ -6701,8 +6724,9 @@ localizeAuthUi();
|
|||||||
function showAuthMenu() {{
|
function showAuthMenu() {{
|
||||||
clearTimeout(authHideTimer);
|
clearTimeout(authHideTimer);
|
||||||
hideOfflineStats();
|
hideOfflineStats();
|
||||||
|
const wasHidden = authMenu.hidden;
|
||||||
authMenu.hidden = false;
|
authMenu.hidden = false;
|
||||||
loadAuthMeta({{silent: true}}).catch(() => {{}});
|
if (wasHidden) loadAuthMeta({{silent: true}}).catch(() => {{}});
|
||||||
}}
|
}}
|
||||||
function scheduleHideAuthMenu() {{
|
function scheduleHideAuthMenu() {{
|
||||||
clearTimeout(authHideTimer);
|
clearTimeout(authHideTimer);
|
||||||
@@ -6887,16 +6911,13 @@ function renderAuthMeta() {{
|
|||||||
renderSshKeyRows(meta.ssh_keys || []);
|
renderSshKeyRows(meta.ssh_keys || []);
|
||||||
}}
|
}}
|
||||||
|
|
||||||
async function loadAuthMeta({{silent = false}} = {{}}) {{
|
async function loadAuthMeta({{silent = false, forceUsername = false}} = {{}}) {{
|
||||||
try {{
|
try {{
|
||||||
const res = await fetch('/api/auth/meta', {{cache: 'no-store'}});
|
const res = await fetch('/api/auth/meta', {{cache: 'no-store'}});
|
||||||
const data = await res.json().catch(() => ({{}}));
|
const data = await res.json().catch(() => ({{}}));
|
||||||
if (!res.ok || !data.ok) throw new Error(data.error || 'Не удалось получить статус авторизации');
|
if (!res.ok || !data.ok) throw new Error(data.error || 'Не удалось получить статус авторизации');
|
||||||
authMeta = data.auth || {{}};
|
authMeta = data.auth || {{}};
|
||||||
if (authForm && authForm.elements && authMeta.username) {{
|
syncAuthUsernameField(forceUsername);
|
||||||
const usernameField = authForm.elements.namedItem('username');
|
|
||||||
if (usernameField) usernameField.value = authMeta.username;
|
|
||||||
}}
|
|
||||||
if (authToggle && authMeta.username) authToggle.textContent = authMeta.username;
|
if (authToggle && authMeta.username) authToggle.textContent = authMeta.username;
|
||||||
renderAuthMeta();
|
renderAuthMeta();
|
||||||
return authMeta;
|
return authMeta;
|
||||||
@@ -7391,7 +7412,8 @@ authForm.addEventListener('submit', async (ev) => {{
|
|||||||
ev.currentTarget.current_password.value = '';
|
ev.currentTarget.current_password.value = '';
|
||||||
ev.currentTarget.password.value = '';
|
ev.currentTarget.password.value = '';
|
||||||
ev.currentTarget.password_confirm.value = '';
|
ev.currentTarget.password_confirm.value = '';
|
||||||
await loadAuthMeta({{silent: true}}).catch(() => {{}});
|
authUsernameDraftDirty = false;
|
||||||
|
await loadAuthMeta({{silent: true, forceUsername: true}}).catch(() => {{}});
|
||||||
}} else {{
|
}} else {{
|
||||||
setAuthMessage(text || 'Не удалось сохранить', true);
|
setAuthMessage(text || 'Не удалось сохранить', true);
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in new issue
Block a user