Многопользовательский режим: авторизация, изоляция данных, лимиты генераций, деплой без VNC
This commit is contained in:
1 parent
0ca55f3818
commit
03555a400f
10 files changed
+1195
-154
No files matched your search
+83
-4
@@ -79,6 +79,13 @@
|
||||
.link:hover { text-decoration: underline; }
|
||||
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
.actions-cell button { padding: 4px 10px; font-size: 12px; }
|
||||
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex;
|
||||
align-items: center; justify-content: center; z-index: 100; }
|
||||
.modal-box { background: var(--card); border: 1px solid var(--border);
|
||||
border-radius: 12px; padding: 20px; max-width: 920px; width: 94%;
|
||||
max-height: 92vh; overflow: auto; }
|
||||
.modal-box img { max-width: 100%; border: 1px solid var(--border);
|
||||
border-radius: 8px; display: block; }
|
||||
::-webkit-scrollbar { width: 10px; height: 10px; }
|
||||
::-webkit-scrollbar-track { background: var(--bg); }
|
||||
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
|
||||
@@ -92,6 +99,10 @@
|
||||
<button id="tab-btn-accounts" class="active" onclick="showTab('accounts')">Аккаунты</button>
|
||||
<button id="tab-btn-vacancies" onclick="showTab('vacancies')">Вакансии</button>
|
||||
</nav>
|
||||
<div style="margin-left:auto; display:flex; align-items:center; gap:12px">
|
||||
<span class="muted" id="current-user"></span>
|
||||
<button class="secondary" onclick="logout()">Выйти</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
@@ -229,10 +240,29 @@
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<!-- ============ МОДАЛКА: ПРОВЕРКА ОТКЛИКА ============ -->
|
||||
<div id="shot-modal" class="modal hidden" onclick="if(event.target===this) closeShot()">
|
||||
<div class="modal-box">
|
||||
<div class="toolbar">
|
||||
<h2 style="margin:0">Проверьте отклик</h2>
|
||||
<div class="spacer"></div>
|
||||
<button class="secondary" onclick="closeShot()">Закрыть</button>
|
||||
</div>
|
||||
<div id="shot-note" class="muted" style="margin-bottom:8px"></div>
|
||||
<img id="shot-img" alt="Скриншот вакансии">
|
||||
<div class="toolbar" style="margin-top:12px">
|
||||
<button id="btn-send" onclick="confirmSend()">Отправить отклик</button>
|
||||
<button class="secondary" onclick="markDone(currentShotId)">Отправил (отметить)</button>
|
||||
<span id="send-note" class="muted"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentAccount = null;
|
||||
let vacancies = [];
|
||||
let generatedTexts = {};
|
||||
let currentShotId = null;
|
||||
|
||||
// ---------- Вкладки ----------
|
||||
function showTab(name) {
|
||||
@@ -249,12 +279,20 @@ async function api(url, opts = {}) {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
...opts,
|
||||
});
|
||||
if (resp.status === 401) { window.location = '/login'; throw new Error('Требуется вход'); }
|
||||
const data = await resp.json().catch(() => ({}));
|
||||
if (!resp.ok) throw new Error(data.error || `HTTP ${resp.status}`);
|
||||
return data;
|
||||
}
|
||||
|
||||
function logout() { window.location = '/logout'; }
|
||||
|
||||
async function loadAccounts() {
|
||||
try {
|
||||
const me = await api('/api/me');
|
||||
const lim = me.limit ? ` · генерации сегодня: ${me.used}/${me.limit}` : '';
|
||||
document.getElementById('current-user').textContent = me.user + lim;
|
||||
} catch (e) { /* 401 уже редиректит */ }
|
||||
const list = await api('/api/accounts');
|
||||
const sel = document.getElementById('acc-select');
|
||||
const prev = sel.value;
|
||||
@@ -543,21 +581,57 @@ function escapeHtml(s) {
|
||||
.replace(/"/g,'"');
|
||||
}
|
||||
|
||||
// ---------- Открытие и отметка ----------
|
||||
// ---------- Открытие, проверка и отправка ----------
|
||||
async function openVacancy(id) {
|
||||
const ta = document.querySelector(`textarea[data-id="${id}"]`);
|
||||
const message = ta ? ta.value : (generatedTexts[id] || '');
|
||||
const note = document.getElementById(`note-${id}`);
|
||||
if (note) { note.textContent = 'Открываю браузер...'; }
|
||||
try {
|
||||
await api(`/api/accounts/${currentAccount}/open`, {
|
||||
const data = await api(`/api/accounts/${currentAccount}/open`, {
|
||||
method: 'POST', body: JSON.stringify({ id, message }),
|
||||
});
|
||||
if (note) note.textContent = data.note || '';
|
||||
if (data.screenshot) {
|
||||
currentShotId = id;
|
||||
document.getElementById('shot-img').src = data.screenshot + '?t=' + Date.now();
|
||||
document.getElementById('shot-note').textContent = data.note || '';
|
||||
document.getElementById('send-note').textContent = '';
|
||||
document.getElementById('btn-send').disabled = false;
|
||||
document.getElementById('shot-modal').classList.remove('hidden');
|
||||
} else {
|
||||
alert(data.note || 'Не удалось открыть вакансию');
|
||||
}
|
||||
} catch (e) {
|
||||
if (note) note.textContent = 'Ошибка: ' + e.message;
|
||||
alert('Ошибка: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
function closeShot() {
|
||||
document.getElementById('shot-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
async function confirmSend() {
|
||||
const btn = document.getElementById('btn-send');
|
||||
const note = document.getElementById('send-note');
|
||||
btn.disabled = true; note.textContent = 'Отправляю...';
|
||||
try {
|
||||
const data = await api(`/api/accounts/${currentAccount}/send`, {
|
||||
method: 'POST', body: JSON.stringify({ id: currentShotId }),
|
||||
});
|
||||
note.textContent = data.note || '';
|
||||
if (data.ok) {
|
||||
const v = vacancies.find(x => x.id === currentShotId);
|
||||
if (v) v.responded = true;
|
||||
renderVacancies();
|
||||
}
|
||||
} catch (e) {
|
||||
note.textContent = 'Ошибка: ' + e.message;
|
||||
}
|
||||
btn.disabled = false;
|
||||
}
|
||||
|
||||
async function markDone(id) {
|
||||
await api(`/api/accounts/${currentAccount}/done`, {
|
||||
method: 'POST', body: JSON.stringify({ id }),
|
||||
@@ -575,9 +649,14 @@ async function resetProgress() {
|
||||
await runSearch();
|
||||
}
|
||||
|
||||
function openLogin() {
|
||||
async function openLogin() {
|
||||
if (!currentAccount) return;
|
||||
window.open(`/api/accounts/${currentAccount}/login`, '_blank');
|
||||
try {
|
||||
const data = await api(`/api/accounts/${currentAccount}/login`);
|
||||
alert(data.note || 'Вход через cookies');
|
||||
} catch (e) {
|
||||
alert('Ошибка: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Старт ----------
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Вход — hh.ru автоотклик</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #0f1117; --card: #1a1d27; --border: #2a2f3a; --text: #e5e7eb;
|
||||
--muted: #9ca3af; --accent: #3b82f6; --accent-hover: #60a5fa;
|
||||
--input-bg: #12141c; --red: #ef4444;
|
||||
}
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
background: var(--bg); color: var(--text); font-size: 14px;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
min-height: 100vh; }
|
||||
.login-box { background: var(--card); border: 1px solid var(--border);
|
||||
border-radius: 12px; padding: 32px; width: 100%; max-width: 360px; }
|
||||
.login-box h1 { font-size: 18px; text-align: center; margin-bottom: 4px; }
|
||||
.login-box .muted { text-align: center; font-size: 13px; margin-bottom: 20px; }
|
||||
input { width: 100%; padding: 10px 12px; border: 1px solid var(--border);
|
||||
border-radius: 8px; font-size: 14px; font-family: inherit;
|
||||
background: var(--input-bg); color: var(--text); margin-bottom: 12px; }
|
||||
input:focus { outline: none; border-color: var(--accent); }
|
||||
button { width: 100%; padding: 10px; border: none; border-radius: 8px;
|
||||
cursor: pointer; font-size: 14px; background: var(--accent); color: #fff;
|
||||
font-weight: 500; }
|
||||
button:hover { background: var(--accent-hover); }
|
||||
.error { color: var(--red); font-size: 13px; text-align: center; margin-top: 10px;
|
||||
min-height: 20px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-box">
|
||||
<h1>hh.ru автоотклик</h1>
|
||||
<p class="muted">Вход в сервис</p>
|
||||
<input type="text" id="username" placeholder="Логин" autocomplete="username" autofocus>
|
||||
<input type="password" id="password" placeholder="Пароль" autocomplete="current-password">
|
||||
<button onclick="doLogin()">Войти</button>
|
||||
<div id="msg" class="error"></div>
|
||||
</div>
|
||||
<script>
|
||||
async function doLogin() {
|
||||
const msg = document.getElementById('msg');
|
||||
msg.textContent = '';
|
||||
try {
|
||||
const resp = await fetch('/login', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
username: document.getElementById('username').value,
|
||||
password: document.getElementById('password').value,
|
||||
}),
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (!resp.ok) { msg.textContent = data.error || 'Ошибка входа'; return; }
|
||||
window.location = '/';
|
||||
} catch (e) { msg.textContent = 'Ошибка сети'; }
|
||||
}
|
||||
document.getElementById('password').addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter') doLogin();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user