mirror of
https://git.sanhost.net/sanasol/hytale-f2p.git
synced 2026-03-01 00:01:48 -03:00
feat: identity protection UI, duplicate guards, name-lock enforcement (v2.4.6)
- Add password set/change/remove with loading states and double-click prevention - Add protected identity deletion flow (server-side password removal first) - Add restore flow for password-protected UUIDs (verify password before saving) - Add UUID duplicate checks in setUuidForUser (prevent accidental overwrites) - Add name-locked error handling in launch flow (server enforces registered name) - Sync shield icon across all identity mutation paths - Refresh identity dropdown after all password/identity operations - Propagate force flag through IPC for legitimate overwrites Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -515,8 +515,9 @@ async function savePlayerName() {
|
||||
// Also refresh the UUID list to update which entry is marked as current
|
||||
await loadAllUuids();
|
||||
|
||||
// Refresh header identity dropdown
|
||||
// Refresh header identity dropdown + shield icon
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
updatePasswordShieldIcon();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error saving player name:', error);
|
||||
@@ -746,6 +747,7 @@ async function performRegenerateUuid() {
|
||||
await loadAllUuids();
|
||||
}
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
updatePasswordShieldIcon();
|
||||
} else {
|
||||
throw new Error(result.error || 'Failed to generate new UUID');
|
||||
}
|
||||
@@ -912,18 +914,61 @@ async function confirmAddIdentity() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.electronAPI && window.electronAPI.setUuidForUser) {
|
||||
const result = await window.electronAPI.setUuidForUser(username, uuid);
|
||||
if (result.success) {
|
||||
const msg = window.i18n ? window.i18n.t('notifications.identityAdded') : 'Identity added successfully!';
|
||||
showNotification(msg, 'success');
|
||||
hideAddIdentityForm();
|
||||
await loadAllUuids();
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
} else {
|
||||
throw new Error(result.error || 'Failed to add identity');
|
||||
// Check if name already exists locally
|
||||
if (window.electronAPI && window.electronAPI.getAllUuidMappings) {
|
||||
const mappings = await window.electronAPI.getAllUuidMappings();
|
||||
const existing = mappings.find(m => m.username.toLowerCase() === username.toLowerCase());
|
||||
if (existing) {
|
||||
showNotification(`Identity "${existing.username}" already exists (UUID: ${existing.uuid.substring(0, 8)}...). Use the identity list to manage it.`, 'error');
|
||||
return;
|
||||
}
|
||||
// Check if UUID already used by another identity
|
||||
const uuidMatch = mappings.find(m => m.uuid.toLowerCase() === uuid.toLowerCase());
|
||||
if (uuidMatch) {
|
||||
showNotification(`This UUID is already used by identity "${uuidMatch.username}". Each identity must have a unique UUID.`, 'error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check username reservation on auth server
|
||||
try {
|
||||
const cfg = await window.electronAPI.loadConfig();
|
||||
const authDomain = cfg.authDomain || 'auth.sanasol.ws';
|
||||
const checkResp = await fetch(`https://${authDomain}/player/username/status/${encodeURIComponent(username)}`);
|
||||
if (checkResp.ok) {
|
||||
const status = await checkResp.json();
|
||||
if (status.reserved) {
|
||||
showNotification(`Username "${username}" is reserved by another player who set a password. Choose a different name.`, 'error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Server check failed — allow creation (fail-open)
|
||||
console.log('[Identity] Server username check skipped:', e.message);
|
||||
}
|
||||
|
||||
// Check if UUID is password-protected on server (restore access flow)
|
||||
let uuidIsProtected = false;
|
||||
let registeredName = null;
|
||||
try {
|
||||
if (window.electronAPI.checkPasswordStatus) {
|
||||
const pwStatus = await window.electronAPI.checkPasswordStatus(uuid);
|
||||
if (pwStatus && pwStatus.hasPassword) {
|
||||
uuidIsProtected = true;
|
||||
registeredName = pwStatus.registeredName || null;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('[Identity] UUID password check skipped:', e.message);
|
||||
}
|
||||
|
||||
if (uuidIsProtected) {
|
||||
// UUID is password-protected — need password to restore it
|
||||
showRestoreProtectedIdentityDialog(username, uuid, registeredName);
|
||||
return;
|
||||
}
|
||||
|
||||
await saveNewIdentity(username, uuid);
|
||||
} catch (error) {
|
||||
console.error('Error adding identity:', error);
|
||||
const msg = window.i18n ? window.i18n.t('notifications.identityAddFailed') : 'Failed to add identity';
|
||||
@@ -931,6 +976,174 @@ async function confirmAddIdentity() {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveNewIdentity(username, uuid) {
|
||||
if (window.electronAPI && window.electronAPI.setUuidForUser) {
|
||||
const result = await window.electronAPI.setUuidForUser(username, uuid);
|
||||
if (result.success) {
|
||||
showNotification('Identity added successfully!', 'success');
|
||||
hideAddIdentityForm();
|
||||
await loadAllUuids();
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
updatePasswordShieldIcon();
|
||||
} else if (result.error === 'duplicate') {
|
||||
showNotification(`Identity "${username}" already exists (UUID: ${result.existingUuid.substring(0, 8)}...). Use the identity list to manage it.`, 'error');
|
||||
} else if (result.error === 'uuid_in_use') {
|
||||
showNotification(`This UUID is already used by identity "${result.existingUsername}". Each identity must have a unique UUID.`, 'error');
|
||||
} else {
|
||||
throw new Error(result.error || 'Failed to add identity');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function showRestoreProtectedIdentityDialog(username, uuid, registeredName) {
|
||||
const existing = document.querySelector('.custom-confirm-modal');
|
||||
if (existing) existing.remove();
|
||||
|
||||
const nameWarning = registeredName && registeredName.toLowerCase() !== username.toLowerCase()
|
||||
? `<p style="color: #f59e0b; margin: 0 0 12px; font-size: 0.9rem;">
|
||||
<i class="fas fa-exclamation-triangle"></i> This UUID is locked to name "<strong>${escapeHtml(registeredName)}</strong>".
|
||||
Your entered name "${escapeHtml(username)}" will be replaced.
|
||||
</p>`
|
||||
: '';
|
||||
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'custom-confirm-modal';
|
||||
overlay.style.cssText = `
|
||||
position: fixed; top: 0; left: 0; right: 0; bottom: 0;
|
||||
background: rgba(0,0,0,0.8); backdrop-filter: blur(4px);
|
||||
z-index: 20000; display: flex; align-items: center; justify-content: center;
|
||||
opacity: 0; transition: opacity 0.3s ease;
|
||||
`;
|
||||
|
||||
const dialog = document.createElement('div');
|
||||
dialog.style.cssText = `
|
||||
background: #1f2937; border-radius: 12px; padding: 0;
|
||||
min-width: 420px; max-width: 520px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.6);
|
||||
border: 1px solid rgba(147, 51, 234, 0.4);
|
||||
transform: scale(0.9); transition: transform 0.3s ease;
|
||||
`;
|
||||
|
||||
dialog.innerHTML = `
|
||||
<div style="padding: 24px; border-bottom: 1px solid rgba(255,255,255,0.1);">
|
||||
<div style="display: flex; align-items: center; gap: 12px; color: #9333ea;">
|
||||
<i class="fas fa-shield-alt" style="font-size: 24px;"></i>
|
||||
<h3 style="margin: 0; font-size: 1.2rem; font-weight: 600;">Restore Protected Identity</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div style="padding: 24px;">
|
||||
<p style="color: #e5e7eb; margin: 0 0 16px; line-height: 1.6;">
|
||||
This UUID is <strong style="color: #22c55e;">password-protected</strong>. Enter the password to restore access.
|
||||
</p>
|
||||
${nameWarning}
|
||||
<div id="restoreError" style="display: none; color: #f87171; background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 0.85rem;"></div>
|
||||
<input type="password" id="restorePasswordInput" style="
|
||||
width: 100%; box-sizing: border-box; padding: 10px 14px;
|
||||
background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.2);
|
||||
border-radius: 8px; color: #fff; font-size: 0.95rem; outline: none;
|
||||
" placeholder="Password" autofocus />
|
||||
</div>
|
||||
<div style="padding: 16px 24px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid rgba(255,255,255,0.1);">
|
||||
<button id="restoreCancelBtn" style="
|
||||
padding: 8px 20px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.2);
|
||||
background: transparent; color: #9ca3af; cursor: pointer; font-size: 0.9rem;
|
||||
">Cancel</button>
|
||||
<button id="restoreConfirmBtn" style="
|
||||
padding: 8px 20px; border-radius: 8px; border: none;
|
||||
background: linear-gradient(135deg, #9333ea, #3b82f6); color: white;
|
||||
cursor: pointer; font-weight: 600; font-size: 0.9rem;
|
||||
">Verify & Restore</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
overlay.appendChild(dialog);
|
||||
document.body.appendChild(overlay);
|
||||
requestAnimationFrame(() => {
|
||||
overlay.style.opacity = '1';
|
||||
dialog.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
const input = overlay.querySelector('#restorePasswordInput');
|
||||
const errorMsg = overlay.querySelector('#restoreError');
|
||||
const confirmBtn = overlay.querySelector('#restoreConfirmBtn');
|
||||
const cancelBtn = overlay.querySelector('#restoreCancelBtn');
|
||||
let busy = false;
|
||||
|
||||
const close = () => { overlay.remove(); };
|
||||
cancelBtn.onclick = close;
|
||||
overlay.addEventListener('click', (e) => { if (e.target === overlay) close(); });
|
||||
|
||||
const doRestore = async () => {
|
||||
if (busy) return;
|
||||
const password = input.value.trim();
|
||||
if (!password) {
|
||||
errorMsg.textContent = 'Password is required';
|
||||
errorMsg.style.display = 'block';
|
||||
input.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
busy = true;
|
||||
confirmBtn.disabled = true;
|
||||
confirmBtn.textContent = 'Verifying...';
|
||||
errorMsg.style.display = 'none';
|
||||
|
||||
try {
|
||||
// Use the registered name if UUID is name-locked
|
||||
const finalName = registeredName || username;
|
||||
|
||||
// Verify password by attempting to get tokens
|
||||
const cfg = await window.electronAPI.loadConfig();
|
||||
const authDomain = cfg.authDomain || 'auth.sanasol.ws';
|
||||
const resp = await fetch(`https://${authDomain}/game-session/new`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ uuid, name: finalName, password, scopes: 'hytale:server hytale:client' })
|
||||
});
|
||||
|
||||
if (resp.status === 401 || resp.status === 429) {
|
||||
const err = await resp.json();
|
||||
errorMsg.textContent = err.error || 'Incorrect password';
|
||||
errorMsg.style.display = 'block';
|
||||
input.value = '';
|
||||
input.focus();
|
||||
busy = false;
|
||||
confirmBtn.disabled = false;
|
||||
confirmBtn.textContent = 'Verify & Restore';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error(`Server returned ${resp.status}`);
|
||||
}
|
||||
|
||||
// Password verified — save identity locally (force to allow the name)
|
||||
close();
|
||||
if (window.electronAPI && window.electronAPI.setUuidForUser) {
|
||||
const result = await window.electronAPI.setUuidForUser(finalName, uuid, true);
|
||||
if (result.success || (result && result.uuid)) {
|
||||
showNotification(`Identity "${finalName}" restored successfully!`, 'success');
|
||||
hideAddIdentityForm();
|
||||
await loadAllUuids();
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
updatePasswordShieldIcon();
|
||||
} else {
|
||||
showNotification(result.error || 'Failed to save identity', 'error');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
errorMsg.textContent = 'Error: ' + e.message;
|
||||
errorMsg.style.display = 'block';
|
||||
busy = false;
|
||||
confirmBtn.disabled = false;
|
||||
confirmBtn.textContent = 'Verify & Restore';
|
||||
}
|
||||
};
|
||||
|
||||
confirmBtn.onclick = doRestore;
|
||||
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') doRestore(); });
|
||||
}
|
||||
|
||||
function toggleAdvancedSection() {
|
||||
if (!uuidAdvancedContent || !uuidAdvancedToggle) return;
|
||||
const isOpen = uuidAdvancedContent.style.display !== 'none';
|
||||
@@ -981,10 +1194,12 @@ async function refreshPasswordStatus() {
|
||||
window.handleSetPassword = async function () {
|
||||
const newPw = document.getElementById('newPasswordInput');
|
||||
const currentPw = document.getElementById('currentPasswordInput');
|
||||
const setBtn = document.getElementById('setPasswordBtn');
|
||||
if (!newPw || !newPw.value || newPw.value.length < 6) {
|
||||
showNotification('Password must be at least 6 characters', 'error');
|
||||
return;
|
||||
}
|
||||
if (setBtn) { setBtn.disabled = true; setBtn.textContent = 'Setting...'; }
|
||||
try {
|
||||
const uuid = await window.electronAPI.getCurrentUuid();
|
||||
const result = await window.electronAPI.setPlayerPassword(uuid, newPw.value, currentPw?.value || null);
|
||||
@@ -994,20 +1209,25 @@ window.handleSetPassword = async function () {
|
||||
if (currentPw) currentPw.value = '';
|
||||
refreshPasswordStatus();
|
||||
updatePasswordShieldIcon();
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
} else {
|
||||
showNotification(result.error || 'Failed to set password', 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
showNotification('Error: ' + e.message, 'error');
|
||||
} finally {
|
||||
if (setBtn) { setBtn.disabled = false; setBtn.textContent = 'Set Password'; }
|
||||
}
|
||||
};
|
||||
|
||||
window.handleRemovePassword = async function () {
|
||||
const currentPw = document.getElementById('currentPasswordInput');
|
||||
const removeBtn = document.getElementById('removePasswordBtn');
|
||||
if (!currentPw || !currentPw.value) {
|
||||
showNotification('Enter your current password to remove it', 'error');
|
||||
return;
|
||||
}
|
||||
if (removeBtn) { removeBtn.disabled = true; removeBtn.textContent = 'Removing...'; }
|
||||
try {
|
||||
const uuid = await window.electronAPI.getCurrentUuid();
|
||||
const result = await window.electronAPI.removePlayerPassword(uuid, currentPw.value);
|
||||
@@ -1016,11 +1236,14 @@ window.handleRemovePassword = async function () {
|
||||
currentPw.value = '';
|
||||
refreshPasswordStatus();
|
||||
updatePasswordShieldIcon();
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
} else {
|
||||
showNotification(result.error || 'Failed to remove password', 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
showNotification('Error: ' + e.message, 'error');
|
||||
} finally {
|
||||
if (removeBtn) { removeBtn.disabled = false; removeBtn.textContent = 'Remove Password'; }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1108,10 +1331,12 @@ window.closePasswordModal = function () {
|
||||
window.handlePasswordModalSet = async function () {
|
||||
const newPw = document.getElementById('pwModalNewPassword');
|
||||
const curPw = document.getElementById('pwModalCurrentPassword');
|
||||
const setBtn = document.getElementById('pwModalSetBtn');
|
||||
if (!newPw || !newPw.value || newPw.value.length < 6) {
|
||||
showNotification('Password must be at least 6 characters', 'error');
|
||||
return;
|
||||
}
|
||||
if (setBtn) { setBtn.disabled = true; const s = setBtn.querySelector('span'); if (s) s.textContent = 'Saving...'; }
|
||||
try {
|
||||
const uuid = await window.electronAPI.getCurrentUuid();
|
||||
const result = await window.electronAPI.setPlayerPassword(uuid, newPw.value, curPw?.value || null);
|
||||
@@ -1121,21 +1346,26 @@ window.handlePasswordModalSet = async function () {
|
||||
newPw.value = '';
|
||||
if (curPw) curPw.value = '';
|
||||
updatePasswordShieldIcon();
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
openPasswordModal(); // refresh modal state
|
||||
} else {
|
||||
showNotification(result.error || 'Failed to set password', 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
showNotification('Error: ' + e.message, 'error');
|
||||
} finally {
|
||||
if (setBtn) { setBtn.disabled = false; const s = setBtn.querySelector('span'); if (s) s.textContent = 'Set Password'; }
|
||||
}
|
||||
};
|
||||
|
||||
window.handlePasswordModalRemove = async function () {
|
||||
const curPw = document.getElementById('pwModalCurrentPassword');
|
||||
const removeBtn = document.getElementById('pwModalRemoveBtn');
|
||||
if (!curPw || !curPw.value) {
|
||||
showNotification('Enter your current password to remove it', 'error');
|
||||
return;
|
||||
}
|
||||
if (removeBtn) { removeBtn.disabled = true; removeBtn.textContent = 'Removing...'; }
|
||||
try {
|
||||
const uuid = await window.electronAPI.getCurrentUuid();
|
||||
const result = await window.electronAPI.removePlayerPassword(uuid, curPw.value);
|
||||
@@ -1143,12 +1373,15 @@ window.handlePasswordModalRemove = async function () {
|
||||
showNotification('Password removed', 'success');
|
||||
curPw.value = '';
|
||||
updatePasswordShieldIcon();
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
openPasswordModal(); // refresh modal state
|
||||
} else {
|
||||
showNotification(result.error || 'Failed to remove password', 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
showNotification('Error: ' + e.message, 'error');
|
||||
} finally {
|
||||
if (removeBtn) { removeBtn.disabled = false; removeBtn.textContent = 'Remove Password'; }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1240,7 +1473,7 @@ async function performSetCustomUuid(uuid) {
|
||||
showNotification(msg, 'error');
|
||||
return;
|
||||
}
|
||||
const result = await window.electronAPI.setUuidForUser(username, uuid);
|
||||
const result = await window.electronAPI.setUuidForUser(username, uuid, true); // force: true — explicit UUID change
|
||||
|
||||
if (result.success) {
|
||||
if (currentUuidDisplay) currentUuidDisplay.value = uuid;
|
||||
@@ -1251,6 +1484,7 @@ async function performSetCustomUuid(uuid) {
|
||||
|
||||
await loadAllUuids();
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
updatePasswordShieldIcon();
|
||||
} else {
|
||||
throw new Error(result.error || 'Failed to set custom UUID');
|
||||
}
|
||||
@@ -1329,8 +1563,9 @@ async function performSwitchToUsername(username) {
|
||||
// Refresh the UUID list to show new "Current" badge
|
||||
await loadAllUuids();
|
||||
|
||||
// Refresh header identity dropdown
|
||||
// Refresh header identity dropdown + shield icon
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
updatePasswordShieldIcon();
|
||||
|
||||
const msg = window.i18n
|
||||
? window.i18n.t('notifications.switchUsernameSuccess').replace('{username}', username)
|
||||
@@ -1348,46 +1583,195 @@ async function performSwitchToUsername(username) {
|
||||
|
||||
window.deleteUuid = async function (username) {
|
||||
try {
|
||||
const message = window.i18n ? window.i18n.t('confirm.deleteUuidMessage').replace('{username}', username) : `Are you sure you want to delete the UUID for "${username}"? This action cannot be undone.`;
|
||||
const title = window.i18n ? window.i18n.t('confirm.deleteUuidTitle') : 'Delete UUID';
|
||||
const confirmBtn = window.i18n ? window.i18n.t('confirm.deleteUuidButton') : 'Delete';
|
||||
const cancelBtn = window.i18n ? window.i18n.t('common.cancel') : 'Cancel';
|
||||
// Look up UUID for this username
|
||||
let uuid = null;
|
||||
if (window.electronAPI && window.electronAPI.getAllUuidMappings) {
|
||||
const mappings = await window.electronAPI.getAllUuidMappings();
|
||||
const entry = mappings.find(m => m.username.toLowerCase() === username.toLowerCase());
|
||||
if (entry) uuid = entry.uuid;
|
||||
}
|
||||
|
||||
showCustomConfirm(
|
||||
message,
|
||||
title,
|
||||
async () => {
|
||||
await performDeleteUuid(username);
|
||||
},
|
||||
null,
|
||||
confirmBtn,
|
||||
cancelBtn
|
||||
);
|
||||
// Check if password-protected
|
||||
let isProtected = false;
|
||||
if (uuid && window.electronAPI && window.electronAPI.checkPasswordStatus) {
|
||||
try {
|
||||
const pwStatus = await window.electronAPI.checkPasswordStatus(uuid);
|
||||
isProtected = pwStatus && pwStatus.hasPassword;
|
||||
} catch (e) {
|
||||
console.log('[Identity] Password status check failed:', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (isProtected) {
|
||||
// Password-protected identity — show warning with password input
|
||||
showPasswordProtectedDeleteDialog(username, uuid);
|
||||
} else {
|
||||
// Normal identity — simple confirm
|
||||
const message = `Are you sure you want to delete the identity "${username}"? This action cannot be undone.`;
|
||||
showCustomConfirm(
|
||||
message,
|
||||
'Delete Identity',
|
||||
async () => { await performDeleteUuid(username); },
|
||||
null,
|
||||
'Delete',
|
||||
'Cancel'
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in deleteUuid:', error);
|
||||
const msg = window.i18n ? window.i18n.t('notifications.uuidDeleteFailed') : 'Failed to delete UUID';
|
||||
showNotification(msg, 'error');
|
||||
showNotification('Failed to delete identity', 'error');
|
||||
}
|
||||
};
|
||||
|
||||
function showPasswordProtectedDeleteDialog(username, uuid) {
|
||||
const existing = document.querySelector('.custom-confirm-modal');
|
||||
if (existing) existing.remove();
|
||||
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'custom-confirm-modal';
|
||||
overlay.style.cssText = `
|
||||
position: fixed; top: 0; left: 0; right: 0; bottom: 0;
|
||||
background: rgba(0,0,0,0.8); backdrop-filter: blur(4px);
|
||||
z-index: 20000; display: flex; align-items: center; justify-content: center;
|
||||
opacity: 0; transition: opacity 0.3s ease;
|
||||
`;
|
||||
|
||||
const dialog = document.createElement('div');
|
||||
dialog.style.cssText = `
|
||||
background: #1f2937; border-radius: 12px; padding: 0;
|
||||
min-width: 420px; max-width: 520px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.6);
|
||||
border: 1px solid rgba(239, 68, 68, 0.4);
|
||||
transform: scale(0.9); transition: transform 0.3s ease;
|
||||
`;
|
||||
|
||||
dialog.innerHTML = `
|
||||
<div style="padding: 24px; border-bottom: 1px solid rgba(255,255,255,0.1);">
|
||||
<div style="display: flex; align-items: center; gap: 12px; color: #ef4444;">
|
||||
<i class="fas fa-shield-alt" style="font-size: 24px;"></i>
|
||||
<h3 style="margin: 0; font-size: 1.2rem; font-weight: 600;">Delete Protected Identity</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div style="padding: 24px;">
|
||||
<p style="color: #e5e7eb; margin: 0 0 16px; line-height: 1.6;">
|
||||
<strong>"${escapeHtml(username)}"</strong> is password-protected. Deleting it will:
|
||||
</p>
|
||||
<ul style="color: #f87171; margin: 0 0 16px; padding-left: 20px; line-height: 1.8;">
|
||||
<li>Remove the password protection from this UUID</li>
|
||||
<li>Release the reserved username "${escapeHtml(username)}"</li>
|
||||
<li>Allow anyone to use this UUID and name</li>
|
||||
</ul>
|
||||
<p style="color: #9ca3af; margin: 0 0 16px; font-size: 0.9rem;">
|
||||
Enter your current password to confirm deletion:
|
||||
</p>
|
||||
<div id="pwDeleteError" style="display: none; color: #f87171; background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 0.85rem;"></div>
|
||||
<input type="password" id="pwDeleteInput" style="
|
||||
width: 100%; box-sizing: border-box; padding: 10px 14px;
|
||||
background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.2);
|
||||
border-radius: 8px; color: #fff; font-size: 0.95rem; outline: none;
|
||||
" placeholder="Current password" autofocus />
|
||||
</div>
|
||||
<div style="padding: 16px 24px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid rgba(255,255,255,0.1);">
|
||||
<button id="pwDeleteCancelBtn" style="
|
||||
padding: 8px 20px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.2);
|
||||
background: transparent; color: #9ca3af; cursor: pointer; font-size: 0.9rem;
|
||||
">Cancel</button>
|
||||
<button id="pwDeleteConfirmBtn" style="
|
||||
padding: 8px 20px; border-radius: 8px; border: none;
|
||||
background: #ef4444; color: white; cursor: pointer; font-weight: 600; font-size: 0.9rem;
|
||||
">Delete & Remove Password</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
overlay.appendChild(dialog);
|
||||
document.body.appendChild(overlay);
|
||||
requestAnimationFrame(() => {
|
||||
overlay.style.opacity = '1';
|
||||
dialog.style.transform = 'scale(1)';
|
||||
});
|
||||
|
||||
const input = overlay.querySelector('#pwDeleteInput');
|
||||
const errorMsg = overlay.querySelector('#pwDeleteError');
|
||||
const confirmBtn = overlay.querySelector('#pwDeleteConfirmBtn');
|
||||
const cancelBtn = overlay.querySelector('#pwDeleteCancelBtn');
|
||||
let busy = false;
|
||||
|
||||
const close = () => { overlay.remove(); };
|
||||
|
||||
cancelBtn.onclick = close;
|
||||
overlay.addEventListener('click', (e) => { if (e.target === overlay) close(); });
|
||||
|
||||
const doDelete = async () => {
|
||||
if (busy) return;
|
||||
const password = input.value.trim();
|
||||
if (!password) {
|
||||
errorMsg.textContent = 'Password is required';
|
||||
errorMsg.style.display = 'block';
|
||||
input.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
busy = true;
|
||||
confirmBtn.disabled = true;
|
||||
confirmBtn.textContent = 'Removing...';
|
||||
errorMsg.style.display = 'none';
|
||||
|
||||
try {
|
||||
// Step 1: Remove password on server (validates current password)
|
||||
const removeResult = await window.electronAPI.removePlayerPassword(uuid, password);
|
||||
if (!removeResult.success) {
|
||||
errorMsg.textContent = removeResult.error || 'Incorrect password';
|
||||
errorMsg.style.display = 'block';
|
||||
input.value = '';
|
||||
input.focus();
|
||||
busy = false;
|
||||
confirmBtn.disabled = false;
|
||||
confirmBtn.textContent = 'Delete & Remove Password';
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2: Also clear saved password if any
|
||||
try {
|
||||
const cfg = await window.electronAPI.loadConfig();
|
||||
if (cfg.savedPasswords && cfg.savedPasswords[uuid]) {
|
||||
delete cfg.savedPasswords[uuid];
|
||||
await window.electronAPI.saveConfig({ savedPasswords: cfg.savedPasswords });
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
|
||||
// Step 3: Delete identity locally
|
||||
close();
|
||||
await performDeleteUuid(username);
|
||||
} catch (e) {
|
||||
errorMsg.textContent = 'Error: ' + e.message;
|
||||
errorMsg.style.display = 'block';
|
||||
busy = false;
|
||||
confirmBtn.disabled = false;
|
||||
confirmBtn.textContent = 'Delete & Remove Password';
|
||||
}
|
||||
};
|
||||
|
||||
confirmBtn.onclick = doDelete;
|
||||
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') doDelete(); });
|
||||
}
|
||||
|
||||
async function performDeleteUuid(username) {
|
||||
try {
|
||||
if (window.electronAPI && window.electronAPI.deleteUuidForUser) {
|
||||
const result = await window.electronAPI.deleteUuidForUser(username);
|
||||
|
||||
if (result.success) {
|
||||
const msg = window.i18n ? window.i18n.t('notifications.uuidDeleteSuccess') : 'UUID deleted successfully!';
|
||||
showNotification(msg, 'success');
|
||||
showNotification('Identity deleted successfully!', 'success');
|
||||
await loadAllUuids();
|
||||
if (window.loadIdentities) window.loadIdentities();
|
||||
updatePasswordShieldIcon();
|
||||
} else {
|
||||
throw new Error(result.error || 'Failed to delete UUID');
|
||||
throw new Error(result.error || 'Failed to delete identity');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting UUID:', error);
|
||||
const msg = window.i18n ? window.i18n.t('notifications.uuidDeleteFailed').replace('{error}', error.message) : `Failed to delete UUID: ${error.message}`;
|
||||
showNotification(msg, 'error');
|
||||
showNotification(`Failed to delete identity: ${error.message}`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user