{% extends "admin/_base.html" %}

{% from "macros/box.html" import m_box %}

{% block content %}
  {%- call m_box(title="Security audit") %}

    <h2>Recent user sessions</h2>

    <table class="table table-striped">
      <thead>
      <tr>
        <th>User name</th>
        <th>Started at</th>
        <th>Ended at</th>
        <th>Duration</th>
        <th>IP Address</th>
      </tr>
      </thead>
      {% for session in sessions %}
        <tr>
          <td><a href="{{ url_for(session.user) }}">{{ session.user.name }}</a>
          </td>
          <td>{{ local_dt(session.started_at) | datetimeformat(format='short') }}</td>
          <td>{%- if session.ended_at %}
            {{ local_dt(session.ended_at) | datetimeformat(format='short') }}{%- else %}
            still active{%- endif %}</td>
          <td>{%- if session.ended_at %}{{ (session.ended_at - session.started_at)|timedeltaformat }}{%- endif %}</td>
          <td>{{ session.ip_address }} ({{ session.country }})</td>
        </tr>
      {% endfor %}
    </table>

  {% endcall %}

{% endblock %}
