archive-ccc8458/video/login.php 2.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sianel — Password</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="/video/sianel.css">
</head>
<body class="page-login">
<a href="/video/"><img class="logo" src="/video/sianel_logo.png" alt="Sianel"></a>
<p>Enter the upload password to manage videos. It's stored only in this browser and sent with each request.</p>

<form id="form">
  <label for="pw">Password</label>
  <input id="pw" type="password" autocomplete="current-password" autofocus>
  <button id="go" type="submit">Save &amp; continue</button>
  <button id="forget" type="button" class="secondary">Delete stored password</button>
</form>

<div id="out"></div>

<script>
const UPLOAD_URL = '/video/admin';
const pwEl  = document.getElementById('pw');
const out   = document.getElementById('out');
const goBtn = document.getElementById('go');

pwEl.value = localStorage.getItem('vidpass') || '';

function setOut(msg, kind) {
  out.textContent = msg;
  out.className = kind || '';
}

document.getElementById('forget').onclick = () => {
  localStorage.removeItem('vidpass');
  pwEl.value = '';
  setOut('Stored password cleared.', '');
};

document.getElementById('form').onsubmit = async (e) => {
  e.preventDefault();
  const pw = pwEl.value.trim();
  if (!pw) { setOut('Enter your password.', 'err'); return; }

  goBtn.disabled = true;
  setOut('Checking…', '');
  try {
    const res = await fetch('/video/api/list', {
      headers: { 'Authorization': 'Bearer ' + pw },
    });
    if (res.ok) {
      localStorage.setItem('vidpass', pw);
      setOut('Correct — redirecting…', 'ok');
      location.href = UPLOAD_URL;
    } else if (res.status === 401) {
      setOut('Incorrect password.', 'err');
    } else if (res.status === 429) {
      setOut('Too many attempts. Wait a few minutes and try again.', 'err');
    } else {
      setOut('Server error: ' + res.status, 'err');
    }
  } catch {
    setOut('Network error — check your connection.', 'err');
  } finally {
    goBtn.disabled = false;
  }
};
</script>
</body>
</html>