{# Source code of the Ubuntu-it website
 # Copyright (C) 2018  Pietro Albini <pietroalbini@ubuntu.com>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published
 # by the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; witout even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU Affero General Public License for more details.
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #}

{% extends "layout.html" %}

{% block title %}Sessioni attive{% endblock %}

{% block content %}
    <div class="page">
        <div class="row">
            <div class="col">
                <h1>Sessioni attive</h1>
                {% if g.auth_sessions_count > 1 %}
                    <p>
                        <a class="btn" href="{{ url_for(".sessions_revoke_all") }}">
                            Disabilita ogni altra sessione
                        </a>
                    </p>
                {% endif %}
            </div>
        </div>
        <div class="row">
            <div class="col">
                <div class="table">
                    <table>
                        <tr>
                            <th>Nome utente</th>
                            <th>Indirizzo IP</th>
                            <th>Inizio</th>
                            <th>Scadenza</th>
                            <th></th>
                            <th></th>
                        </tr>
                        {% for session in sessions %}
                        <tr>
                            <td>{{ session.nickname }}</td>
                            <td>{{ session.ip }}</td>
                            <td>{{ session.created_at|format_timestamp }}</td>
                            <td>{{ session.expires_at|format_timestamp }}</td>
                            <td>
                                <a href="{{ url_for(".sessions_show", id=session.id) }}">
                                    Dettagli
                                </a>
                            </td>
                            <td>
                                {% if session.id == g.auth_id %}
                                Sessione corrente
                                {% else %}
                                <a href="{{ url_for(".sessions_revoke", id=session.id) }}">
                                    Disabilita sessione
                                </a>
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </table>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
