oprava zmeny hesla
This commit is contained in:
@@ -1259,18 +1259,27 @@ async function doMcpChange() {
|
||||
const u = JSON.parse(localStorage.getItem('user') || '{}');
|
||||
if (pass.length < 6) { err.textContent = 'Heslo musí mať aspoň 6 znakov.'; return; }
|
||||
if (pass !== pass2) { err.textContent = 'Heslá sa nezhodujú.'; return; }
|
||||
|
||||
// 1. Zmeniť heslo — server zároveň nastaví MustChangePassword = false
|
||||
const res = await fetch(`${API}/auth/reset-password`, {
|
||||
method:'POST', headers:{'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ email: u.email, newPassword: pass, code: null })
|
||||
});
|
||||
if (res.ok) {
|
||||
// Update stored user to clear mustChangePassword flag
|
||||
u.mustChangePassword = false;
|
||||
localStorage.setItem('user', JSON.stringify(u));
|
||||
document.getElementById('mcp-modal').classList.remove('open');
|
||||
} else {
|
||||
err.textContent = await res.text();
|
||||
if (!res.ok) { err.textContent = await res.text(); return; }
|
||||
|
||||
// 2. Znovu prihlásiť — dostaneme nový token s mustChangePassword: false
|
||||
const loginRes = await fetch(`${API}/auth/login`, {
|
||||
method:'POST', headers:{'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ email: u.email, password: pass })
|
||||
});
|
||||
if (loginRes.ok) {
|
||||
const d = await loginRes.json();
|
||||
saveAuth(d);
|
||||
// Aktualizuj meno/avatar v topbare (zostáva rovnaké, ale token je nový)
|
||||
document.getElementById('hdr-user').textContent = d.username;
|
||||
document.getElementById('hdr-avatar').textContent = d.username ? d.username[0].toUpperCase() : '?';
|
||||
}
|
||||
document.getElementById('mcp-modal').classList.remove('open');
|
||||
}
|
||||
|
||||
// ═══ ADMIN PANEL ═══
|
||||
|
||||
Reference in New Issue
Block a user