{% extends "base.html" %}
{% block title %}Account · tit{% endblock %}
{% block content %}
  <h1>Account</h1>
  <dl>
    <dt>Username</dt>
    <dd>{{ username }}</dd>
    <dt>Administrator</dt>
    <dd>{% if administrator %}Yes{% else %}No{% endif %}</dd>
  </dl>
  <div class="two-column">
  <section>
  <h2>Public profile</h2>
  <form action="/account/profile" method="post">
    <input type="hidden" name="csrf" value="{{ csrf }}">
    <div class="field">
      <label for="profile-bio">Bio</label>
      <textarea id="profile-bio" name="bio" maxlength="512" rows="5">{{ bio }}</textarea>
    </div>
    <div class="field">
      <label for="profile-email">Public contact email</label>
      <input id="profile-email" type="email" name="contact-email" maxlength="254" value="{{ contact_email }}">
    </div>
    <button type="submit">Save profile</button>
  </form>
  <p><a href="/{{ username }}">View your public profile</a></p>
  </section>
  <section>
  <h2>Create repository</h2>
  <form action="/account/repositories" method="post">
    <input type="hidden" name="csrf" value="{{ csrf }}">
    <p>
      <label for="repository-name">Name</label>
      <input id="repository-name" name="name" required maxlength="100" pattern="([a-z0-9]|[a-z0-9][a-z0-9._-]*[a-z0-9])">
    </p>
    <button type="submit">Create repository</button>
  </form>
  <h2>Feeds</h2>
  <p><a href="/feeds">Manage private feed tokens</a></p>
  <h2>Sessions</h2>
  <p><a href="/logout">Log out all sessions</a></p>
  <h2>SSH keys</h2>
  <ul class="key-list">
    {% for key in keys %}
    <li class="key-card">
      <h3>{{ key.label }}</h3>
      <dl>
        <dt>Fingerprint</dt>
        <dd><code>{{ key.fingerprint }}</code></dd>
        <dt>Created</dt>
        <dd>{{ key.created_at }}</dd>
        <dt>Last used</dt>
        <dd>{{ key.last_used_at }}</dd>
        <dt>State</dt>
        <dd>{% if key.active %}Active{% else %}Revoked{% endif %}</dd>
      </dl>
        {% if key.active %}
          {% if active_key_count > 1 %}
      <form action="/account/keys/revoke" method="post">
        <input type="hidden" name="csrf" value="{{ csrf }}">
        <input type="hidden" name="fingerprint" value="{{ key.fingerprint }}">
        <button type="submit">Revoke</button>
      </form>
          {% else %}
      <p>This is your final active key.</p>
          {% endif %}
        {% endif %}
    </li>
    {% endfor %}
  </ul>
  <h3>Add SSH key</h3>
  <form action="/account/keys/add" method="post">
    <input type="hidden" name="csrf" value="{{ csrf }}">
    <div class="field">
      <label for="key-label">Label</label>
      <input id="key-label" name="label" required maxlength="80">
    </div>
    <div class="field">
      <label for="public-key">SSH public key</label>
      <textarea id="public-key" name="public-key" required rows="4"></textarea>
    </div>
    <button type="submit">Add key</button>
  </form>
  </section>
  </div>
{% endblock %}
