{% extends "base.html" %}
{% load i18n %}
{% load translations %}
{% load permissions %}
{% load crispy_forms_tags %}
{% load authnames %}

{% block breadcrumbs %}
<li><a href="{% url 'manage' %}">{% trans "Manage" %}</a></li>
<li><a href="{% url 'manage-users' %}">{% trans "Users" %}</a></li>
{% endblock %}

{% block content %}

{% if users is not None %}
{% for user in users %}
<div class="panel panel-default">
    <div class="panel-heading">
      <a href="{% url "admin:weblate_auth_user_change" object_id=user.id %}" class="btn btn-primary pull-right flip">{% trans "Edit" %}</a>
      <h4 class="panel-title"><a href="{{ user.get_absolute_url }}">{{ user.username }}</a> &mdash; {{ user.full_name }} &mdash; {{ user.email }}</h4>
      <div class="clearfix"></div>
    </div>
    <table class="table">
    <tr><th>{% trans "Last login" %}</th><td colspan="6">{{ user.last_login|date:"DATETIME_FORMAT" }}</td></tr>
    <tr><th>{% trans "Date joined" %}</th><td colspan="6">{{ user.date_joined|date:"DATETIME_FORMAT" }}</td></tr>
    <tr><th colspan="7" class="active">{% trans "Current user identities" %}</th></tr>
    <tr>
        <th>{% trans "Identity" %}</th>
        <th>{% trans "User ID" %}</th>
        <th colspan="5">{% trans "E-mail" %}</th>
    </tr>
    {% for social in user.social_auth.all %}
    <tr>
        <th>{% auth_name social.provider ' ' %}</th>
        <td>{{ social.uid }}</td>
        <td colspan="5">{% for verified in social.verifiedemail_set.all %}{{ verified.email }}{% endfor %}</td>
    </tr>
    {% endfor %}
    {% with billings=user.billing_set.all %}
      {% if billings %}
        <tr><th colspan="7" class="active">{% trans "User billings" %}</th></tr>
        {% include "billing/list.html" with objects=billings hide_table_tag=1 show_expiry=1 show_removal=1 %}
      {% endif %}
    {% endwith %}
    <tr><th colspan="7" class="active">{% trans "Audit log" %}</th></tr>
    <tr>
        <th>{% trans "When" %}</th>
        <th colspan="2">{% trans "Account activity" %}</th>
        <th colspan="2">{% trans "IP address" %}</th>
        <th colspan="2">{% trans "User agent" %}</th>
    </tr>
    {% for log in user.auditlog_set.order %}
    <tr>
        <td>{{ log.timestamp|date:"DATETIME_FORMAT" }}</td>
        <td colspan="2">{{ log.get_message }}</td>
        <td colspan="2">{{ log.address }}</td>
        <td colspan="2">{{ log.user_agent }}</td>
    </tr>
    {% endfor %}
    </table>
</div>
{% empty %}
{% trans "No matching user found." as msg %}
{% show_message "warning" msg %}
{% endfor %}
{% endif %}

<form method="GET" action="{% url "manage-users-check" %}">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Check user access" %}</h4></div>
  <div class="panel-body">
  {{ form|crispy }}
  </div>
  <div class="panel-footer">
  <input type="submit" class="btn btn-primary" value="{% trans "Search" %}" />
  </div>
</div>
</form>

{% endblock %}
