foxygit / foxygit Log in
A tiny read-only git web frontend — browse bare repos with just PHP and git, no database, no framework.
commits tags

/views/account.php · 3.33 KB

raw
<?php
/** @var string $username @var bool $isAdmin @var array $keys @var ?string $newKey
 *  @var ?string $error @var string $csrf */
$warnIcon = '<svg class="icon" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">'
    . '<path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Z"></path>'
    . '<rect x="7.25" y="4" width="1.5" height="5.5" rx="0.75"></rect><circle cx="8" cy="11.75" r="0.9"></circle></svg>';
$okIcon = '<svg class="icon" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">'
    . '<path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13Z"></path>'
    . '<path d="M4.5 8.2 7 10.7l4.5-5" style="fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round"></path></svg>';
$plusIcon = '<svg class="icon" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">'
    . '<rect x="7" y="2" width="2" height="12" rx="1"></rect><rect x="2" y="7" width="12" height="2" rx="1"></rect></svg>';
?>
<h1>Account</h1>
<p class="desc">Logged in as <strong><?= h($username) ?></strong><?= $isAdmin ? ' (admin)' : '' ?>.</p>

<?php if ($error !== null): ?>
<div class="msg-error"><?= $warnIcon ?><div><?= h($error) ?></div></div>
<?php endif; ?>

<?php if ($newKey !== null): ?>
<div class="msg-ok">
  <?= $okIcon ?>
  <div>
    <p><strong>New API key created.</strong> Copy it now — it won't be shown again:</p>
    <div class="key-reveal"><code><?= h($newKey) ?></code></div>
    <p>Use it as the password when <code>git push</code> asks for one over HTTPS (any username works).</p>
  </div>
</div>
<?php endif; ?>

<div class="box">
  <div class="box-header">API keys</div>
  <?php if (!$keys): ?>
  <table><tr><td class="desc">No API keys yet.</td></tr></table>
  <?php else: ?>
  <table>
    <thead><tr><th>Label</th><th>Created</th><th>Last used</th><th></th></tr></thead>
    <?php foreach ($keys as $hash => $key): ?>
    <tr>
      <td><?= h($key['label']) ?></td>
      <td class="desc"><?= h(format_relative_time($key['created'])) ?></td>
      <td class="desc"><?= $key['last_used'] !== null ? h(format_relative_time($key['last_used'])) : 'never' ?></td>
      <td class="num">
        <form class="inline-form" method="post" action="?a=account" onsubmit="return confirm('Revoke this key? Anything using it will stop working immediately.');">
          <input type="hidden" name="csrf" value="<?= h($csrf) ?>">
          <input type="hidden" name="sub" value="revoke-key">
          <input type="hidden" name="hash" value="<?= h($hash) ?>">
          <button type="submit" class="danger">Revoke</button>
        </form>
      </td>
    </tr>
    <?php endforeach; ?>
  </table>
  <?php endif; ?>
</div>

<div class="box">
  <div class="box-header"><?= $plusIcon ?> New API key</div>
  <form class="form" method="post" action="?a=account">
    <input type="hidden" name="csrf" value="<?= h($csrf) ?>">
    <input type="hidden" name="sub" value="create-key">
    <div class="field-row">
      <input type="text" id="label" name="label" placeholder="label, e.g. laptop" maxlength="60"
             aria-label="New API key label">
      <button type="submit" class="primary">Create API key</button>
    </div>
    <p class="field-hint desc">The key is shown once, right after you create it. Use it as the password for <code>git push</code> over HTTPS.</p>
  </form>
</div>