2.4 KiB · text History 7a00c02
{% extends "root.html" %}

{% block content %}
<div class="space-y-6">
  <h2 class="text-2xl font-bold text-accent">Devices</h2>
  <p class="text-sm opacity-70">
    Pair the Android app by scanning a QR made here, or just sign in from the app
    with your username and password. Each phone gets its own token; revoke one to
    sign that device out. Scripts can use a token too:
    <code>Authorization: Bearer &lt;token&gt;</code>.
  </p>

  <form method="post" action="/devices" class="card bg-base-200 p-4 flex flex-wrap gap-3 items-end">
    <label class="form-control">
      <span class="label-text text-xs">Name</span>
      <input class="input input-bordered input-sm" type="text" name="label" placeholder="Pixel 8" maxlength="100"/>
    </label>
    <label class="form-control">
      <span class="label-text text-xs">Expires in days (blank: never)</span>
      <input class="input input-bordered input-sm w-40" type="number" min="1" name="days"/>
    </label>
    <button class="btn btn-primary btn-sm" type="submit"><i class="fas fa-qrcode"></i> Make a pairing QR</button>
  </form>

  {% if tokens | length == 0 %}
    <p class="text-sm opacity-70">No devices yet.</p>
  {% else %}
  <div class="overflow-x-auto border border-base-300 rounded-box">
    <table class="table table-sm">
      <thead><tr><th>Name</th><th>Token</th><th>Last used</th><th>Expires</th><th></th></tr></thead>
      <tbody>
        {% for t in tokens %}
        {% set expired = t.expires_at and (t.expires_at | string) < (now | string) %}
        <tr class="{{ 'opacity-50' if expired else '' }}">
          <td>{{ t.label or "—" }}{% if expired %} <span class="badge badge-warning badge-sm">expired</span>{% endif %}</td>
          <td><code class="text-xs">{{ t.prefix }}…</code></td>
          <td class="text-xs">{% if t.last_used_at %}{{ t.last_used_at | timesince }} ago{% else %}never{% endif %}</td>
          <td class="text-xs">{{ t.expires_at[:10] if t.expires_at else "never" }}</td>
          <td class="text-right">
            <form method="post" action="/devices/{{ t.id }}/revoke">
              <button class="btn btn-ghost btn-xs text-error" type="submit" hx-confirm="Revoke {{ t.label or 'this token' }}? That device will be signed out.">Revoke</button>
            </form>
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
  {% endif %}
</div>
{% endblock %}