safety-audit/index.html

141 lines
12 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>ПАБ — Вход</title>
</head>
<body style="margin:0;padding:0;font-family:sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;background:linear-gradient(135deg,#0F1218,#1a2332)">
<div style="background:#fff;padding:40px;border-radius:14px;width:380px;max-width:90vw;box-shadow:0 8px 40px rgba(0,0,0,0.3)">
<h1 style="font-size:18px;text-align:center;margin-bottom:4px">🛡️ ПАБ</h1>
<p style="text-align:center;color:#666;font-size:12px;margin-bottom:20px">Система ПАБ</p>
<div id="tabs" style="display:flex;margin-bottom:16px;border:2px solid #ddd;border-radius:8px;overflow:hidden">
<button id="tLogin" style="flex:1;padding:8px;font-weight:700;background:#00B4D8;color:#fff;border:none;cursor:pointer;font-size:13px">Вход</button>
<button id="tReg" style="flex:1;padding:8px;font-weight:700;background:#fff;color:#666;border:none;cursor:pointer;font-size:13px">Регистрация</button>
</div>
<!-- Вход -->
<div id="fLogin">
<input id="lu" placeholder="Логин" style="width:100%;padding:10px;margin-bottom:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
<input type="password" id="lp" placeholder="Пароль" style="width:100%;padding:10px;margin-bottom:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
<button id="btnLogin" style="width:100%;padding:12px;background:#00B4D8;color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:700;cursor:pointer">Войти</button>
<div id="loginErr" style="color:red;font-size:13px;text-align:center;display:none;margin-top:8px">Неверный логин или пароль</div>
</div>
<!-- Регистрация -->
<div id="fReg" style="display:none">
<input id="rLogin" placeholder="Логин" style="width:100%;padding:10px;margin-bottom:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
<input id="rPass" placeholder="Пароль (мин. 3)" type="password" style="width:100%;padding:10px;margin-bottom:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
<input id="rName" placeholder="ФИО" style="width:100%;padding:10px;margin-bottom:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
<input id="rEmail" placeholder="Email" style="width:100%;padding:10px;margin-bottom:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
<select id="rRole" style="width:100%;padding:10px;margin-bottom:10px;border:2px solid #ddd;border-radius:8px;font-size:13px">
<option value="">Должность</option><option>Директор департамента ЦА</option><option>Директор департамента филиала</option><option>Региональный директор</option><option>Директор ДЭСД</option><option>Начальник ТУСМ</option><option>Руководитель СП</option><option>Начальник центра/службы/цеха</option><option>Начальник участка</option><option>Инженер БиОТ</option><option>Работник отдела БиОТ</option>
</select>
<select id="rFreq" style="width:100%;padding:10px;margin-bottom:10px;border:2px solid #ddd;border-radius:8px;font-size:13px">
<option value="">Периодичность ПАБ</option><option value="2,month">2 раза в месяц</option><option value="1,month">1 раз в месяц</option><option value="1,quarter">1 раз в квартал</option><option value="1,halfyear">1 раз в полгода</option>
</select>
<div style="display:flex;gap:8px;margin-bottom:10px">
<input id="rBranch" placeholder="Филиал" style="flex:1;padding:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
<input id="rDept" placeholder="Подразделение" style="flex:1;padding:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
</div>
<div style="display:flex;gap:8px;margin-bottom:10px">
<input id="rRegion" placeholder="Регион" style="flex:1;padding:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
<input id="rOblast" placeholder="Область" style="flex:1;padding:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
</div>
<input id="rCity" placeholder="Город / село" style="width:100%;padding:10px;margin-bottom:10px;border:2px solid #ddd;border-radius:8px;box-sizing:border-box">
<button id="btnReg" style="width:100%;padding:12px;background:#00B4D8;color:#fff;border:none;border-radius:8px;font-size:14px;font-weight:700;cursor:pointer">Зарегистрироваться</button>
<div id="regErr" style="color:red;font-size:13px;text-align:center;display:none;margin-top:8px"></div>
<div id="regOk" style="color:#2D6A4F;font-size:13px;text-align:center;display:none;margin-top:8px">✅ Успешно! Теперь войдите.</div>
</div>
</div>
<script>
// Табы
document.getElementById('tLogin').onclick=function(){document.getElementById('fLogin').style.display='block';document.getElementById('fReg').style.display='none';this.style.background='#00B4D8';this.style.color='#fff';document.getElementById('tReg').style.background='#fff';document.getElementById('tReg').style.color='#666'};
document.getElementById('tReg').onclick=function(){document.getElementById('fLogin').style.display='none';document.getElementById('fReg').style.display='block';this.style.background='#00B4D8';this.style.color='#fff';document.getElementById('tLogin').style.background='#fff';document.getElementById('tLogin').style.color='#666'};
// ВХОД
document.getElementById('btnLogin').onclick=function(){
var u=document.getElementById('lu').value.trim().toLowerCase();
var p=document.getElementById('lp').value.trim();
var err=document.getElementById('loginErr');err.style.display='none';
// 1. Admin
if(u==='admin'&&p==='admin'){
sessionStorage.setItem('pab_user',JSON.stringify({login:'admin',name:'Администратор',role:'Руководитель',freq:'0,month',email:'admin@telecom.kz',branch:'АО Казахтелеком',dept:'ЦА',region:'Центральный',oblast:'—',city:'г. Астана'}));
location.href='app.html';return;
}
// 2. Проверяем localStorage
var users={};
try{users=JSON.parse(localStorage.getItem('pab_users')||'{}');}catch(e){}
if(users[u]&&users[u].pass===p){
sessionStorage.setItem('pab_user',JSON.stringify({login:u,name:users[u].name,role:users[u].role,freq:users[u].freq||'',email:users[u].email||'',branch:users[u].branch||'',dept:users[u].dept||'',region:users[u].region||'',oblast:users[u].oblast||'',city:users[u].city||''}));
location.href='app.html';return;
}
// 3. Проверяем Supabase
var btn=document.getElementById('btnLogin');btn.textContent='Проверка...';
fetch('https://znexbjafkvyjffffbhlf.supabase.co/rest/v1/users?login=eq.'+encodeURIComponent(u),{
headers:{'apikey':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InpuZXhiamFma3Z5amZmZmZiaGxmIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc4MDY0NDE4MiwiZXhwIjoyMDk2MjIwMTgyfQ.5pOYTkL5eCmpSHBY3EwKof6NVKt7tL4Fn8xUAKM8itE','Authorization':'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InpuZXhiamFma3Z5amZmZmZiaGxmIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc4MDY0NDE4MiwiZXhwIjoyMDk2MjIwMTgyfQ.5pOYTkL5eCmpSHBY3EwKof6NVKt7tL4Fn8xUAKM8itE'}
}).then(function(r){return r.json()}).then(function(d){
if(d.length>0&&d[0].pass===p){
var ud=d[0];users[u]={pass:ud.pass,name:ud.name,email:ud.email,role:ud.role,freq:ud.freq,branch:ud.branch,dept:ud.dept,region:ud.region,oblast:ud.oblast,city:ud.city};
localStorage.setItem('pab_users',JSON.stringify(users));
sessionStorage.setItem('pab_user',JSON.stringify({login:u,name:ud.name,role:ud.role,freq:ud.freq||'',email:ud.email||'',branch:ud.branch||'',dept:ud.dept||'',region:ud.region||'',oblast:ud.oblast||'',city:ud.city||''}));
location.href='app.html';
}else{btn.textContent='Войти';err.textContent='Неверный логин или пароль';err.style.display='block';}
}).catch(function(e){btn.textContent='Войти';err.textContent='Ошибка соединения';err.style.display='block';});
};
document.getElementById('lp').onkeydown=function(e){if(e.key==='Enter')document.getElementById('btnLogin').onclick();};
// РЕГИСТРАЦИЯ
document.getElementById('btnReg').onclick=function(){
var l=document.getElementById('rLogin').value.trim().toLowerCase();
var p=document.getElementById('rPass').value.trim();
var n=document.getElementById('rName').value.trim();
var em=document.getElementById('rEmail').value.trim();
var r=document.getElementById('rRole').value;
var fr=document.getElementById('rFreq').value;
var br=document.getElementById('rBranch').value.trim();
var dp=document.getElementById('rDept').value.trim();
var rg=document.getElementById('rRegion').value.trim();
var ob=document.getElementById('rOblast').value.trim();
var ct=document.getElementById('rCity').value.trim();
var err=document.getElementById('regErr'),ok=document.getElementById('regOk');
err.style.display='none';ok.style.display='none';
if(!l||l.length<2){err.textContent='Логин мин. 2 символа';err.style.display='block';return}
if(!p||p.length<3){err.textContent='Пароль мин. 3 символа';err.style.display='block';return}
if(!n){err.textContent='Укажите ФИО';err.style.display='block';return}
if(!em||em.indexOf('@')<0){err.textContent='Укажите Email';err.style.display='block';return}
if(!r){err.textContent='Выберите должность';err.style.display='block';return}
if(!fr){err.textContent='Выберите периодичность';err.style.display='block';return}
if(!br||!dp||!rg||!ct){err.textContent='Заполните все поля';err.style.display='block';return}
// Проверяем localStorage
var users={};try{users=JSON.parse(localStorage.getItem('pab_users')||'{}');}catch(e){}
if(users[l]){err.textContent='Логин уже занят';err.style.display='block';return}
// Сохраняем локально
users[l]={pass:p,name:n,email:em,role:r,freq:fr,branch:br,dept:dp,region:rg,oblast:ob,city:ct};
localStorage.setItem('pab_users',JSON.stringify(users));
// Отправляем в Supabase
var btn=document.getElementById('btnReg');btn.textContent='Сохранение...';
fetch('https://znexbjafkvyjffffbhlf.supabase.co/rest/v1/users',{
method:'POST',
headers:{'apikey':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InpuZXhiamFma3Z5amZmZmZiaGxmIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc4MDY0NDE4MiwiZXhwIjoyMDk2MjIwMTgyfQ.5pOYTkL5eCmpSHBY3EwKof6NVKt7tL4Fn8xUAKM8itE','Authorization':'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InpuZXhiamFma3Z5amZmZmZiaGxmIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc4MDY0NDE4MiwiZXhwIjoyMDk2MjIwMTgyfQ.5pOYTkL5eCmpSHBY3EwKof6NVKt7tL4Fn8xUAKM8itE','Content-Type':'application/json','Prefer':'resolution=merge-duplicates'},
body:JSON.stringify({login:l,pass:p,name:n,email:em,role:r,freq:fr,branch:br,dept:dp,region:rg,oblast:ob,city:ct})
}).then(function(r){
btn.textContent='Зарегистрироваться';
if(r.ok){ok.style.display='block';document.getElementById('lu').value=l;setTimeout(function(){ok.style.display='none';document.getElementById('tLogin').click()},2000)}
else{alert('Сохранено локально. Supabase вернул ошибку '+r.status+'. С другого устройства вход может не работать.');ok.style.display='block';document.getElementById('lu').value=l;setTimeout(function(){ok.style.display='none';document.getElementById('tLogin').click()},2000)}
}).catch(function(){btn.textContent='Зарегистрироваться';alert('Сохранено локально. Supabase недоступен.');ok.style.display='block';document.getElementById('lu').value=l;setTimeout(function(){ok.style.display='none';document.getElementById('tLogin').click()},2000)});
};
</script>
</body>
</html>