fix: askPassword closure — pw declared inside function (was global ref)
This commit is contained in:
+9
-4
@@ -2474,8 +2474,10 @@ window.toggleEditConsulta = async function() {
|
||||
openEditModal(full);
|
||||
};
|
||||
|
||||
// Pede senha admin — retorna Promise<boolean>
|
||||
function askPassword() {
|
||||
return new Promise(resolve => {
|
||||
const pw = config.admin_password;
|
||||
const overlay = document.createElement('div');
|
||||
overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:999999;display:flex;align-items:center;justify-content:center;';
|
||||
overlay.id = 'pw-modal';
|
||||
@@ -2485,21 +2487,24 @@ function askPassword() {
|
||||
<input type="password" id="pw-input" placeholder="Digite a senha..." style="width:100%;padding:10px;font-size:14px;border:1px solid #ccc;border-radius:6px;box-sizing:border-box;margin-bottom:12px" />
|
||||
<div id="pw-error" style="color:#c0272d;font-size:12px;margin-bottom:8px;display:none">Senha incorreta</div>
|
||||
<div style="display:flex;gap:8px;justify-content:center">
|
||||
<button onclick="document.getElementById('pw-modal').remove();window._pwResult=false;window._pwResolve&&window._pwResolve(false)" style="padding:8px 16px;background:#888;color:#fff;border:none;border-radius:6px;cursor:pointer">Cancelar</button>
|
||||
<button id="pw-cancel-btn" style="padding:8px 16px;background:#888;color:#fff;border:none;border-radius:6px;cursor:pointer">Cancelar</button>
|
||||
<button id="pw-ok-btn" style="padding:8px 16px;background:#e65100;color:#fff;border:none;border-radius:6px;cursor:pointer">OK</button>
|
||||
</div>
|
||||
</div>`;
|
||||
document.body.appendChild(overlay);
|
||||
const inp = document.getElementById('pw-input');
|
||||
inp.focus();
|
||||
window._pwResolve = resolve;
|
||||
|
||||
document.getElementById('pw-cancel-btn').addEventListener('click', () => {
|
||||
document.getElementById('pw-modal').remove();
|
||||
resolve(false);
|
||||
});
|
||||
inp.addEventListener('keydown', e => { if (e.key === 'Enter') document.getElementById('pw-ok-btn').click(); });
|
||||
document.getElementById('pw-ok-btn').addEventListener('click', () => {
|
||||
const val = document.getElementById('pw-input').value;
|
||||
if (val === pw) {
|
||||
document.getElementById('pw-modal').remove();
|
||||
window._pwResult = true;
|
||||
window._pwResolve && window._pwResolve(true);
|
||||
resolve(true);
|
||||
} else {
|
||||
document.getElementById('pw-error').style.display = 'block';
|
||||
inp.value = '';
|
||||
|
||||
Reference in New Issue
Block a user