feat(client): config token-first — apenas token + URL + pasta + senha local
continuous-integration/webhook Falha no build do client (VPS4)
continuous-integration/webhook Falha no build do client (VPS4)
Config UI simplificado: - Remove campos: Nome do PC, E-mail do Servidor, Senha do Servidor, Usuário do Painel (7 campos → 4 campos). - Mantém: Token, URL do Servidor, Pasta para Monitorar, Senha do Painel. - Botão "Verificar": chama GET /api/auth/device-info e exibe card com Clínica e PC identificados antes de salvar. - Ao salvar: valida token no servidor, clientName vem do pc_name retornado. - Token já salvo: verificado automaticamente ao abrir as configurações. - Login simplificado: pede só a senha (sem campo de usuário). client-monitor.js: - server-identified: se pcName vier do servidor, atualiza config.clientName localmente para manter em sincronia com o cadastro. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1073,6 +1073,15 @@ function connectToServer() {
|
|||||||
? `Clínica: ${info.clinicName}`
|
? `Clínica: ${info.clinicName}`
|
||||||
: '⚠️ Clínica não identificada — configure o Token no painel de configurações';
|
: '⚠️ Clínica não identificada — configure o Token no painel de configurações';
|
||||||
addLog(`✅ Identificação confirmada: PC=${info.name} | ${clinicLabel}`);
|
addLog(`✅ Identificação confirmada: PC=${info.name} | ${clinicLabel}`);
|
||||||
|
|
||||||
|
// Se o servidor enviou o pcName autoritativo (via machine_token),
|
||||||
|
// atualiza o clientName local para manter em sincronia.
|
||||||
|
if (info.pcName && info.pcName !== config.clientName) {
|
||||||
|
addLog(`🔄 Nome do PC atualizado pelo servidor: ${info.pcName}`);
|
||||||
|
config.clientName = info.pcName;
|
||||||
|
try { persistConfig(); } catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
isIdentified = true;
|
isIdentified = true;
|
||||||
sendStatusToParent();
|
sendStatusToParent();
|
||||||
});
|
});
|
||||||
|
|||||||
+52
-46
@@ -25,22 +25,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- MAIN CONTENT AREA -->
|
|
||||||
<main class="main-content">
|
<main class="main-content">
|
||||||
|
|
||||||
<!-- 1. LOGIN SCREEN -->
|
<!-- 1. TELA DE LOGIN -->
|
||||||
<div id="login-container" class="container-panel">
|
<div id="login-container" class="container-panel">
|
||||||
<div class="panel-header">
|
<div class="panel-header">
|
||||||
<h2>🔒 Acesso Restrito</h2>
|
<h2>🔒 Acesso Restrito</h2>
|
||||||
<p>Insira as credenciais do Administrador para alterar as configurações.</p>
|
<p>Insira a senha do painel para alterar as configurações.</p>
|
||||||
</div>
|
</div>
|
||||||
<form id="login-form" class="login-form">
|
<form id="login-form" class="login-form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="login-username">👤 Usuário</label>
|
<label for="login-password">🔑 Senha do Painel</label>
|
||||||
<input type="text" id="login-username" placeholder="Digite o usuário" required autocomplete="off">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="login-password">🔑 Senha</label>
|
|
||||||
<input type="password" id="login-password" placeholder="Digite a senha" required>
|
<input type="password" id="login-password" placeholder="Digite a senha" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="login-actions">
|
<div class="login-actions">
|
||||||
@@ -50,64 +45,76 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 2. CONFIGURATION SCREEN (Hidden by default, shown after login or on first run) -->
|
<!-- 2. TELA DE CONFIGURAÇÃO -->
|
||||||
<div id="settings-container" class="container-panel hidden">
|
<div id="settings-container" class="container-panel hidden">
|
||||||
|
|
||||||
|
<!-- Card de identidade do dispositivo (preenchido após validar o token) -->
|
||||||
|
<div id="device-card" class="hidden" style="
|
||||||
|
background: linear-gradient(135deg, rgba(124,77,255,0.12), rgba(0,229,255,0.08));
|
||||||
|
border: 1px solid rgba(124,77,255,0.3);
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 14px 18px;
|
||||||
|
margin-bottom: 18px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;">
|
||||||
|
<span style="font-size: 2rem; line-height:1;">🏥</span>
|
||||||
|
<div>
|
||||||
|
<div id="device-clinic" style="font-weight:700; font-size:1rem;"></div>
|
||||||
|
<div id="device-pc" style="font-size:0.8rem; opacity:0.7; margin-top:2px;"></div>
|
||||||
|
</div>
|
||||||
|
<span style="margin-left:auto; background:rgba(34,197,94,0.15); color:#16a34a; border:1px solid rgba(34,197,94,0.3); border-radius:20px; padding:3px 12px; font-size:0.75rem; font-weight:700;">✓ Token válido</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form id="config-form" class="config-form">
|
<form id="config-form" class="config-form">
|
||||||
<div class="form-grid">
|
<div class="form-grid">
|
||||||
<!-- Machine Name - High Priority -->
|
|
||||||
|
<!-- Token do servidor (único campo de credencial) -->
|
||||||
<div class="form-group full-width">
|
<div class="form-group full-width">
|
||||||
<label for="clientName">🖥️ Nome Deste Computador</label>
|
<label for="token">🔑 Token do Dispositivo</label>
|
||||||
<input type="text" id="clientName" placeholder="Ex: PC-CONSULTORIO-1" required autocomplete="off">
|
<div style="display:flex; gap:8px;">
|
||||||
<small class="help-text">Insira um nome único identificável no painel da ScoreOdonto.</small>
|
<input type="text" id="token"
|
||||||
|
placeholder="Cole aqui o token gerado no painel do servidor"
|
||||||
|
autocomplete="off" spellcheck="false"
|
||||||
|
style="font-family:'JetBrains Mono',monospace; font-size:0.82rem; flex:1;">
|
||||||
|
<button type="button" id="btn-verify-token" class="btn btn-outline" style="white-space:nowrap;">
|
||||||
|
<span id="verify-spinner" class="spinner"></span>
|
||||||
|
<span id="verify-text">Verificar</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<small class="help-text">Token gerado em <b>Clínicas e Acessos</b> no painel do servidor. Ao verificar, a clínica e o PC são identificados automaticamente.</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Server URL -->
|
<!-- URL do servidor -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="serverUrl">🌐 URL do Servidor</label>
|
<label for="serverUrl">🌐 URL do Servidor</label>
|
||||||
<input type="text" id="serverUrl" placeholder="https://rx.scoreodonto.com" required autocomplete="off">
|
<input type="text" id="serverUrl"
|
||||||
|
placeholder="https://rx.scoreodonto.com"
|
||||||
|
autocomplete="off">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Monitor Path -->
|
<!-- Pasta a monitorar -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="monitorPath">📁 Pasta para Monitorar</label>
|
<label for="monitorPath">📁 Pasta para Monitorar</label>
|
||||||
<input type="text" id="monitorPath" placeholder="C:\ProgramData\RF\Dental Sensor\Images" required autocomplete="off">
|
<input type="text" id="monitorPath"
|
||||||
|
placeholder="C:\ProgramData\RF\Dental Sensor\Images"
|
||||||
|
autocomplete="off">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Server Email -->
|
<!-- Senha do painel local -->
|
||||||
<div class="form-group">
|
|
||||||
<label for="serverEmail">📧 E-mail do Servidor</label>
|
|
||||||
<input type="email" id="serverEmail" placeholder="email@clinica.com" required autocomplete="off">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Server Password -->
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="serverPassword">🔑 Senha do Servidor</label>
|
|
||||||
<input type="password" id="serverPassword" placeholder="Sua senha no servidor" required autocomplete="off">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Server Token -->
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="token">🔑 Token do Servidor</label>
|
|
||||||
<input type="text" id="token" placeholder="Token de 48 caracteres do cadastro" required autocomplete="off">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Local Admin Username -->
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="adminUsername">👤 Usuário do Painel</label>
|
|
||||||
<input type="text" id="adminUsername" placeholder="Usuário admin" required autocomplete="off">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Local Admin Password -->
|
|
||||||
<div class="form-group full-width">
|
<div class="form-group full-width">
|
||||||
<label for="adminPassword">🔒 Senha do Painel (Bloqueio de Configurações)</label>
|
<label for="adminPassword">🔒 Senha do Painel Local</label>
|
||||||
<div class="password-wrapper">
|
<div class="password-wrapper">
|
||||||
<input type="password" id="adminPassword" placeholder="Senha do painel" required autocomplete="off">
|
<input type="password" id="adminPassword"
|
||||||
|
placeholder="Protege o acesso a estas configurações"
|
||||||
|
autocomplete="off">
|
||||||
<button type="button" id="toggle-admin-password" class="btn-toggle-password">👁️</button>
|
<button type="button" id="toggle-admin-password" class="btn-toggle-password">👁️</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ACTIONS -->
|
<!-- AÇÕES -->
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="button" id="btn-test" class="btn btn-outline">
|
<button type="button" id="btn-test" class="btn btn-outline">
|
||||||
<span id="test-spinner" class="spinner"></span>
|
<span id="test-spinner" class="spinner"></span>
|
||||||
@@ -139,7 +146,6 @@
|
|||||||
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="config-ui.js"></script>
|
<script src="config-ui.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+183
-191
@@ -1,94 +1,74 @@
|
|||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
// Containers
|
// ── Elementos ──────────────────────────────────────────────────
|
||||||
const loginContainer = document.getElementById('login-container');
|
const loginContainer = document.getElementById('login-container');
|
||||||
const settingsContainer = document.getElementById('settings-container');
|
const settingsContainer = document.getElementById('settings-container');
|
||||||
|
const loginForm = document.getElementById('login-form');
|
||||||
// Login Form Elements
|
|
||||||
const loginForm = document.getElementById('login-form');
|
|
||||||
const loginUsernameInput = document.getElementById('login-username');
|
|
||||||
const loginPasswordInput = document.getElementById('login-password');
|
const loginPasswordInput = document.getElementById('login-password');
|
||||||
const btnLoginCancel = document.getElementById('btn-login-cancel');
|
const btnLoginCancel = document.getElementById('btn-login-cancel');
|
||||||
|
|
||||||
// Config Form Elements
|
const configForm = document.getElementById('config-form');
|
||||||
const configForm = document.getElementById('config-form');
|
const tokenInput = document.getElementById('token');
|
||||||
const clientNameInput = document.getElementById('clientName');
|
const serverUrlInput = document.getElementById('serverUrl');
|
||||||
const serverUrlInput = document.getElementById('serverUrl');
|
const monitorPathInput = document.getElementById('monitorPath');
|
||||||
const monitorPathInput = document.getElementById('monitorPath');
|
|
||||||
const serverEmailInput = document.getElementById('serverEmail');
|
|
||||||
const serverPasswordInput = document.getElementById('serverPassword');
|
|
||||||
const tokenInput = document.getElementById('token');
|
|
||||||
const adminUsernameInput = document.getElementById('adminUsername');
|
|
||||||
const adminPasswordInput = document.getElementById('adminPassword');
|
const adminPasswordInput = document.getElementById('adminPassword');
|
||||||
|
|
||||||
// Action Buttons
|
const deviceCard = document.getElementById('device-card');
|
||||||
const btnTest = document.getElementById('btn-test');
|
const deviceClinic = document.getElementById('device-clinic');
|
||||||
const testSpinner = document.getElementById('test-spinner');
|
const devicePc = document.getElementById('device-pc');
|
||||||
const testText = document.getElementById('test-text');
|
|
||||||
const btnCancel = document.getElementById('btn-cancel');
|
const btnVerifyToken = document.getElementById('btn-verify-token');
|
||||||
|
const verifySpinner = document.getElementById('verify-spinner');
|
||||||
|
const verifyText = document.getElementById('verify-text');
|
||||||
|
|
||||||
|
const btnTest = document.getElementById('btn-test');
|
||||||
|
const testSpinner = document.getElementById('test-spinner');
|
||||||
|
const testText = document.getElementById('test-text');
|
||||||
|
const btnCancel = document.getElementById('btn-cancel');
|
||||||
|
const btnLoginCancelBtn = document.getElementById('btn-login-cancel');
|
||||||
|
|
||||||
let loadedConfig = null;
|
let loadedConfig = null;
|
||||||
|
let verifiedDevice = null; // { clinicName, pcName } após verificação
|
||||||
|
|
||||||
// Show message notification
|
// ── Toast ───────────────────────────────────────────────────────
|
||||||
function showToast(message, type = 'success') {
|
function showToast(message, type = 'success') {
|
||||||
const toast = document.getElementById('toast');
|
const toast = document.getElementById('toast');
|
||||||
toast.textContent = message;
|
toast.textContent = message;
|
||||||
toast.className = `toast show ${type}`;
|
toast.className = `toast show ${type}`;
|
||||||
setTimeout(() => {
|
setTimeout(() => { toast.className = 'toast'; }, 3500);
|
||||||
toast.className = 'toast';
|
|
||||||
}, 3000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize layout and load config
|
// ── Inicialização ───────────────────────────────────────────────
|
||||||
try {
|
try {
|
||||||
if (window.api && window.api.getVersion) {
|
if (window.api?.getVersion) {
|
||||||
const version = await window.api.getVersion();
|
const version = await window.api.getVersion();
|
||||||
const badge = document.getElementById('app-version-badge');
|
const badge = document.getElementById('app-version-badge');
|
||||||
if (badge) badge.innerText = `Client v${version}`;
|
if (badge) badge.innerText = `Client v${version}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.api && window.api.getLogs) {
|
|
||||||
const logs = await window.api.getLogs();
|
|
||||||
if (logs && logs.length > 0) {
|
|
||||||
const terminalLogs = document.getElementById('terminal-logs');
|
|
||||||
if (terminalLogs) {
|
|
||||||
terminalLogs.innerHTML = ''; // clear wait message
|
|
||||||
logs.forEach(log => {
|
|
||||||
const div = document.createElement('div');
|
|
||||||
div.className = 'log-line';
|
|
||||||
div.textContent = log;
|
|
||||||
terminalLogs.appendChild(div);
|
|
||||||
});
|
|
||||||
terminalLogs.scrollTop = terminalLogs.scrollHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadedConfig = await window.api.getConfig();
|
loadedConfig = await window.api.getConfig();
|
||||||
|
|
||||||
// Populate settings form
|
serverUrlInput.value = loadedConfig.serverUrl || 'https://rx.scoreodonto.com';
|
||||||
if (loadedConfig.clientName === 'DIGITE-O-NOME-DA-MAQUINA') {
|
monitorPathInput.value = loadedConfig.monitorPath || 'C:\\ProgramData\\RF\\Dental Sensor\\Images';
|
||||||
clientNameInput.value = '';
|
tokenInput.value = loadedConfig.token || '';
|
||||||
} else {
|
adminPasswordInput.value = loadedConfig.adminPassword || '';
|
||||||
clientNameInput.value = loadedConfig.clientName || '';
|
|
||||||
|
// Se já tem token salvo, verificar automaticamente e mostrar card
|
||||||
|
if (loadedConfig.token && loadedConfig.token.includes('-')) {
|
||||||
|
await verifyToken(loadedConfig.token, loadedConfig.serverUrl, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
serverUrlInput.value = loadedConfig.serverUrl || 'https://rx.scoreodonto.com';
|
// Carregar logs no terminal
|
||||||
monitorPathInput.value = loadedConfig.monitorPath || 'C:\\ProgramData\\RF\\Dental Sensor\\Images';
|
if (window.api?.getLogs) {
|
||||||
serverEmailInput.value = loadedConfig.serverEmail || '';
|
const logs = await window.api.getLogs();
|
||||||
serverPasswordInput.value = loadedConfig.serverPassword || '';
|
if (logs?.length) renderLogs(logs);
|
||||||
tokenInput.value = loadedConfig.token || '';
|
}
|
||||||
adminUsernameInput.value = loadedConfig.adminUsername || 'admin';
|
|
||||||
adminPasswordInput.value = loadedConfig.adminPassword || 'admin';
|
|
||||||
|
|
||||||
// Check if it is a first run (clientName not configured yet)
|
|
||||||
const isFirstRun = !loadedConfig.clientName || loadedConfig.clientName === 'DIGITE-O-NOME-DA-MAQUINA';
|
|
||||||
|
|
||||||
|
// Primeira execução: exibe config direto sem pedir senha
|
||||||
|
const isFirstRun = !loadedConfig.adminPassword;
|
||||||
if (isFirstRun) {
|
if (isFirstRun) {
|
||||||
// Bypass login overlay and show setup screen directly
|
|
||||||
loginContainer.classList.add('hidden');
|
loginContainer.classList.add('hidden');
|
||||||
settingsContainer.classList.remove('hidden');
|
settingsContainer.classList.remove('hidden');
|
||||||
} else {
|
} else {
|
||||||
// Show login screen
|
|
||||||
loginContainer.classList.remove('hidden');
|
loginContainer.classList.remove('hidden');
|
||||||
settingsContainer.classList.add('hidden');
|
settingsContainer.classList.add('hidden');
|
||||||
}
|
}
|
||||||
@@ -96,117 +76,145 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
showToast('Erro ao carregar configurações: ' + e.message, 'error');
|
showToast('Erro ao carregar configurações: ' + e.message, 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Login Submit
|
// ── Verificar token com o servidor ─────────────────────────────
|
||||||
|
async function verifyToken(token, serverUrl, showFeedback = true) {
|
||||||
|
if (!token || !token.includes('-')) {
|
||||||
|
if (showFeedback) showToast('Token inválido — deve ser o UUID gerado no painel.', 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const url = (serverUrl || serverUrlInput.value).trim().replace(/\/$/, '');
|
||||||
|
if (!url) {
|
||||||
|
if (showFeedback) showToast('Informe a URL do servidor antes de verificar.', 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${url}/api/auth/device-info?token=${encodeURIComponent(token)}`);
|
||||||
|
const data = await res.json();
|
||||||
|
if (data.success) {
|
||||||
|
verifiedDevice = data;
|
||||||
|
deviceClinic.textContent = `🏥 ${data.clinicName}`;
|
||||||
|
devicePc.textContent = `🖥️ ${data.pcName}`;
|
||||||
|
deviceCard.classList.remove('hidden');
|
||||||
|
if (showFeedback) showToast(`Dispositivo identificado: ${data.clinicName} — ${data.pcName}`, 'success');
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
verifiedDevice = null;
|
||||||
|
deviceCard.classList.add('hidden');
|
||||||
|
if (showFeedback) showToast('Token inválido: ' + data.error, 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
verifiedDevice = null;
|
||||||
|
deviceCard.classList.add('hidden');
|
||||||
|
if (showFeedback) showToast('Erro ao verificar token: ' + e.message, 'error');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Botão verificar token
|
||||||
|
btnVerifyToken.addEventListener('click', async () => {
|
||||||
|
btnVerifyToken.disabled = true;
|
||||||
|
verifySpinner.style.display = 'inline-block';
|
||||||
|
verifyText.textContent = ' Verificando...';
|
||||||
|
await verifyToken(tokenInput.value.trim(), serverUrlInput.value.trim(), true);
|
||||||
|
btnVerifyToken.disabled = false;
|
||||||
|
verifySpinner.style.display = 'none';
|
||||||
|
verifyText.textContent = 'Verificar';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Re-verificar quando URL muda (e já tem token)
|
||||||
|
serverUrlInput.addEventListener('change', () => {
|
||||||
|
if (tokenInput.value.trim().includes('-')) {
|
||||||
|
verifyToken(tokenInput.value.trim(), serverUrlInput.value.trim(), false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Login ───────────────────────────────────────────────────────
|
||||||
loginForm.addEventListener('submit', (e) => {
|
loginForm.addEventListener('submit', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
const correctPassword = loadedConfig?.adminPassword || 'admin';
|
||||||
const username = loginUsernameInput.value.trim();
|
if (loginPasswordInput.value === correctPassword) {
|
||||||
const password = loginPasswordInput.value;
|
showToast('Autenticado!', 'success');
|
||||||
|
|
||||||
const correctUsername = loadedConfig.adminUsername || 'admin';
|
|
||||||
const correctPassword = loadedConfig.adminPassword || 'admin';
|
|
||||||
|
|
||||||
if (username === correctUsername && password === correctPassword) {
|
|
||||||
showToast('Autenticado com sucesso!', 'success');
|
|
||||||
// Transition panels
|
|
||||||
loginContainer.classList.add('hidden');
|
loginContainer.classList.add('hidden');
|
||||||
settingsContainer.classList.remove('hidden');
|
settingsContainer.classList.remove('hidden');
|
||||||
} else {
|
} else {
|
||||||
showToast('Usuário ou senha inválidos.', 'error');
|
showToast('Senha incorreta.', 'error');
|
||||||
loginPasswordInput.value = '';
|
loginPasswordInput.value = '';
|
||||||
loginPasswordInput.focus();
|
loginPasswordInput.focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle Config Form Submit
|
// ── Salvar configurações ────────────────────────────────────────
|
||||||
configForm.addEventListener('submit', async (e) => {
|
configForm.addEventListener('submit', async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const name = clientNameInput.value.trim();
|
const token = tokenInput.value.trim();
|
||||||
if (!name || name === 'DIGITE-O-NOME-DA-MAQUINA') {
|
|
||||||
showToast('Por favor, informe um nome válido para o computador.', 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const serverUrl = serverUrlInput.value.trim();
|
const serverUrl = serverUrlInput.value.trim();
|
||||||
const serverEmail = serverEmailInput.value.trim();
|
const monitorPath = monitorPathInput.value.trim();
|
||||||
const serverPassword = serverPasswordInput.value;
|
const adminPassword = adminPasswordInput.value.trim();
|
||||||
const token = tokenInput.value.trim();
|
|
||||||
|
|
||||||
// Validar credenciais no servidor
|
if (!token) {
|
||||||
const saveSpinner = document.getElementById('save-spinner');
|
showToast('Cole o Token do Dispositivo antes de salvar.', 'error');
|
||||||
const saveBtn = document.getElementById('btn-save');
|
|
||||||
saveBtn.disabled = true;
|
|
||||||
if (saveSpinner) saveSpinner.style.display = 'inline-block';
|
|
||||||
|
|
||||||
try {
|
|
||||||
showToast('Validando credenciais com o servidor...', 'info');
|
|
||||||
const verifyResult = await window.api.verifyCredentials(serverUrl, serverEmail, serverPassword, token);
|
|
||||||
|
|
||||||
if (saveSpinner) saveSpinner.style.display = 'none';
|
|
||||||
saveBtn.disabled = false;
|
|
||||||
|
|
||||||
if (!verifyResult.success) {
|
|
||||||
showToast('Falha na validação: ' + verifyResult.error, 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
showToast('Credenciais confirmadas pelo servidor!', 'success');
|
|
||||||
} catch (authErr) {
|
|
||||||
if (saveSpinner) saveSpinner.style.display = 'none';
|
|
||||||
saveBtn.disabled = false;
|
|
||||||
showToast('Erro ao conectar ao servidor para validar: ' + authErr.message, 'error');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!serverUrl) {
|
||||||
|
showToast('Informe a URL do servidor.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verificar token antes de salvar
|
||||||
|
const saveBtn = document.getElementById('btn-save');
|
||||||
|
const saveSpinner = document.getElementById('save-spinner');
|
||||||
|
saveBtn.disabled = true;
|
||||||
|
saveSpinner.style.display = 'inline-block';
|
||||||
|
|
||||||
|
const valid = await verifyToken(token, serverUrl, true);
|
||||||
|
saveBtn.disabled = false;
|
||||||
|
saveSpinner.style.display = 'none';
|
||||||
|
|
||||||
|
if (!valid) return;
|
||||||
|
|
||||||
|
// clientName vem do pc_name do servidor (verifiedDevice)
|
||||||
|
const clientName = verifiedDevice?.pcName || loadedConfig?.clientName || 'PC-CLINICA';
|
||||||
|
|
||||||
const newConfig = {
|
const newConfig = {
|
||||||
...loadedConfig,
|
...loadedConfig,
|
||||||
clientName: name,
|
serverUrl,
|
||||||
serverUrl: serverUrl,
|
monitorPath: monitorPath || 'C:\\ProgramData\\RF\\Dental Sensor\\Images',
|
||||||
monitorPath: monitorPathInput.value.trim(),
|
clientName,
|
||||||
apiKey: token, // Salva o token também como apiKey para compatibilidade retroativa
|
token,
|
||||||
serverEmail: serverEmail,
|
apiKey: token, // compatibilidade retroativa
|
||||||
serverPassword: serverPassword,
|
serverEmail: '', // não mais necessário
|
||||||
token: token,
|
serverPassword: '', // não mais necessário
|
||||||
adminUsername: adminUsernameInput.value.trim(),
|
adminUsername: 'admin',
|
||||||
adminPassword: adminPasswordInput.value.trim(),
|
adminPassword: adminPassword || 'admin',
|
||||||
clientType: 'windows'
|
clientType: 'windows',
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const success = await window.api.saveConfig(newConfig);
|
const success = await window.api.saveConfig(newConfig);
|
||||||
if (success) {
|
if (success) {
|
||||||
showToast('Configurações salvas!');
|
showToast('Configurações salvas! Reconectando...');
|
||||||
setTimeout(() => {
|
setTimeout(() => window.api.closeWindow(), 1200);
|
||||||
window.api.closeWindow();
|
|
||||||
}, 1000);
|
|
||||||
} else {
|
} else {
|
||||||
showToast('Falha ao salvar as configurações.', 'error');
|
showToast('Falha ao gravar as configurações.', 'error');
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast('Erro: ' + err.message, 'error');
|
showToast('Erro: ' + err.message, 'error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle Test Connection
|
// ── Testar conexão ──────────────────────────────────────────────
|
||||||
btnTest.addEventListener('click', async () => {
|
btnTest.addEventListener('click', async () => {
|
||||||
const url = serverUrlInput.value.trim();
|
const url = serverUrlInput.value.trim();
|
||||||
if (!url) {
|
if (!url) { showToast('Informe a URL do servidor.', 'error'); return; }
|
||||||
showToast('Informe a URL do servidor.', 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
btnTest.disabled = true;
|
btnTest.disabled = true;
|
||||||
testSpinner.style.display = 'inline-block';
|
testSpinner.style.display = 'inline-block';
|
||||||
testText.textContent = ' Testando...';
|
testText.textContent = ' Testando...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await window.api.testServer(url);
|
const result = await window.api.testServer(url);
|
||||||
if (result.success) {
|
if (result.success) showToast('Conexão estabelecida com sucesso!', 'success');
|
||||||
showToast('Conexão estabelecida com sucesso!', 'success');
|
else showToast('Falha: ' + result.error, 'error');
|
||||||
} else {
|
|
||||||
showToast('Falha na conexão: ' + result.error, 'error');
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast('Erro: ' + err.message, 'error');
|
showToast('Erro: ' + err.message, 'error');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -216,70 +224,54 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Toggle Admin Password Visibility
|
// ── Toggle senha do painel ──────────────────────────────────────
|
||||||
const toggleAdminPassword = document.getElementById('toggle-admin-password');
|
document.getElementById('toggle-admin-password')?.addEventListener('click', () => {
|
||||||
if (toggleAdminPassword) {
|
const type = adminPasswordInput.type === 'password' ? 'text' : 'password';
|
||||||
toggleAdminPassword.addEventListener('click', () => {
|
adminPasswordInput.type = type;
|
||||||
const type = adminPasswordInput.getAttribute('type') === 'password' ? 'text' : 'password';
|
document.getElementById('toggle-admin-password').textContent = type === 'password' ? '👁️' : '🙈';
|
||||||
adminPasswordInput.setAttribute('type', type);
|
});
|
||||||
toggleAdminPassword.textContent = type === 'password' ? '👁️' : '🙈';
|
|
||||||
|
// ── Minimizar ───────────────────────────────────────────────────
|
||||||
|
btnCancel?.addEventListener('click', () => window.api.closeWindow());
|
||||||
|
btnLoginCancelBtn?.addEventListener('click', () => window.api.closeWindow());
|
||||||
|
|
||||||
|
// ── Terminal de logs ────────────────────────────────────────────
|
||||||
|
function renderLogs(logs) {
|
||||||
|
const terminal = document.getElementById('terminal-logs');
|
||||||
|
if (!terminal) return;
|
||||||
|
terminal.innerHTML = '';
|
||||||
|
logs.forEach(log => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.className = 'log-line';
|
||||||
|
div.textContent = log;
|
||||||
|
terminal.appendChild(div);
|
||||||
});
|
});
|
||||||
|
terminal.scrollTop = terminal.scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Minimize / Close Window
|
if (window.api?.onLog) {
|
||||||
btnCancel.addEventListener('click', () => {
|
|
||||||
window.api.closeWindow();
|
|
||||||
});
|
|
||||||
|
|
||||||
btnLoginCancel.addEventListener('click', () => {
|
|
||||||
window.api.closeWindow();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Terminal Logs
|
|
||||||
const terminalLogs = document.getElementById('terminal-logs');
|
|
||||||
const btnCopyLogs = document.getElementById('btn-copy-logs');
|
|
||||||
|
|
||||||
if (window.api.onLog) {
|
|
||||||
window.api.onLog((log) => {
|
window.api.onLog((log) => {
|
||||||
if (terminalLogs) {
|
const terminal = document.getElementById('terminal-logs');
|
||||||
// remove the waiting message if present
|
if (!terminal) return;
|
||||||
const waitingMsg = terminalLogs.querySelector('.log-line');
|
const wait = terminal.querySelector('.log-line');
|
||||||
if (waitingMsg && waitingMsg.textContent.includes('Aguardando logs')) {
|
if (wait?.textContent.includes('Aguardando logs')) terminal.innerHTML = '';
|
||||||
terminalLogs.innerHTML = '';
|
const div = document.createElement('div');
|
||||||
}
|
div.className = 'log-line';
|
||||||
|
div.textContent = log;
|
||||||
const div = document.createElement('div');
|
terminal.appendChild(div);
|
||||||
div.className = 'log-line';
|
terminal.scrollTop = terminal.scrollHeight;
|
||||||
div.textContent = log;
|
while (terminal.children.length > 100) terminal.removeChild(terminal.firstChild);
|
||||||
terminalLogs.appendChild(div);
|
|
||||||
|
|
||||||
// Auto scroll to bottom
|
|
||||||
terminalLogs.scrollTop = terminalLogs.scrollHeight;
|
|
||||||
|
|
||||||
// Keep max 100 logs
|
|
||||||
while (terminalLogs.children.length > 100) {
|
|
||||||
terminalLogs.removeChild(terminalLogs.firstChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (btnCopyLogs && terminalLogs) {
|
document.getElementById('btn-copy-logs')?.addEventListener('click', () => {
|
||||||
btnCopyLogs.addEventListener('click', () => {
|
const terminal = document.getElementById('terminal-logs');
|
||||||
const logsText = Array.from(terminalLogs.children)
|
const text = Array.from(terminal.children).map(el => el.textContent).join('\n');
|
||||||
.map(el => el.textContent)
|
navigator.clipboard.writeText(text).then(() => {
|
||||||
.join('\n');
|
const btn = document.getElementById('btn-copy-logs');
|
||||||
|
const orig = btn.innerHTML;
|
||||||
navigator.clipboard.writeText(logsText).then(() => {
|
btn.innerHTML = '✅ Copiado';
|
||||||
const icon = document.getElementById('copy-icon');
|
setTimeout(() => { btn.innerHTML = orig; }, 2000);
|
||||||
const originalText = btnCopyLogs.innerHTML;
|
|
||||||
btnCopyLogs.innerHTML = '✅ Copiado';
|
|
||||||
setTimeout(() => {
|
|
||||||
btnCopyLogs.innerHTML = originalText;
|
|
||||||
}, 2000);
|
|
||||||
}).catch(err => {
|
|
||||||
showToast('Erro ao copiar logs', 'error');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user