{% extends "pretixcontrol/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% block title %}{% trans "User" %}{% endblock %}
{% block content %}
    <h1>{% trans "User" %} {{ user.email }}</h1>
    <p>
        {% if user.auth_backend == "native" %}
            <form action="{% url "control:users.reset" id=user.pk %}" method="post" class="form-inline helper-display-inline">
                {% csrf_token %}
                <button class="btn btn-default">{% trans "Send password reset email" %}</button>
            </form>
        {% endif %}
        {% if user.require_2fa %}
            <form action="{% url "control:users.emergencytoken" id=user.pk %}" method="post" class="form-inline helper-display-inline">
                {% csrf_token %}
                <button class="btn btn-default">{% trans "Generate 2FA emergency token" %}</button>
            </form>
        {% endif %}
        <form action="{% url "control:users.impersonate" id=user.pk %}" method="post" class="form-inline helper-display-inline">
            {% csrf_token %}
            <button class="btn btn-default">{% trans "Impersonate user" %}</button>
        </form>
        <a href="{% url "control:users.anonymize" id=user.pk %}" class="btn btn-default">{% trans "Anonymize" %}</a>
    </p>
    <div class="row">
        <div class="col-md-10 col-xs-12">
            <form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
                {% csrf_token %}
                {% bootstrap_form_errors form %}
                <fieldset>
                    <legend>{% trans "Base settings" %}</legend>
                    {% bootstrap_field form.is_active layout='control' %}
                    {% bootstrap_field form.fullname layout='control' %}
                    {% bootstrap_field form.locale layout='control' %}
                    {% bootstrap_field form.timezone layout='control' %}
                    {% bootstrap_field form.is_staff layout='control' %}
                </fieldset>
                <fieldset>
                    <legend>{% trans "Log-in settings" %}</legend>
                    <div class="form-group">
                        <label class="col-md-3 control-label">{% trans "Authentication backend" %}</label>
                        <div class="col-md-9">
                            <input name="text" value="{{ backend }}" class="form-control" disabled>
                        </div>
                    </div>
                    {% if user.auth_backend_identifier %}
                        <div class="form-group">
                            <label class="col-md-3 control-label">{% trans "External identifier" %}</label>
                            <div class="col-md-9">
                                <input name="text" value="{{ user.auth_backend_identifier }}" class="form-control" disabled>
                            </div>
                        </div>
                    {% endif %}
                    {% bootstrap_field form.email layout='control' %}
                    {% if form.new_pw %}
                        {% bootstrap_field form.new_pw layout='control' %}
                        {% bootstrap_field form.new_pw_repeat layout='control' %}
                    {% endif %}
                    {% bootstrap_field form.last_login layout='control' %}
                    {% bootstrap_field form.require_2fa layout='control' %}
                    {% bootstrap_field form.needs_password_change layout='control' %}
                </fieldset>
                <fieldset>
                    <legend>{% trans "Team memberships" %}</legend>
                    <ul>
                        {% for t in teams %}
                            <li>
                                <a href="{% url "control:organizer.team" organizer=t.organizer.slug team=t.pk %}">
                                    {% blocktrans trimmed with team=t.name organizer=t.organizer.name %}
                                        Team "{{ team }}" of organizer "{{ organizer }}"
                                    {% endblocktrans %}
                                </a>
                            </li>
                        {% endfor %}
                    </ul>
                </fieldset>
                <div class="form-group submit-group">
                    <button type="submit" class="btn btn-primary btn-save">
                        {% trans "Save" %}
                    </button>
                </div>
            </form>
        </div>
        <div class="col-xs-12 col-lg-2">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        {% trans "User history" %}
                    </h3>
                </div>
                {% include "pretixcontrol/includes/logs.html" with obj=user %}
                <li class="list-group-item logentry">
                    <p class="meta">
                        <span class="fa fa-clock-o"></span> {{ user.date_joined|date:"SHORT_DATETIME_FORMAT" }}
                    </p>
                    <p>
                        {% trans "User created." %}
                    </p>
                </li>
            </div>
        </div>
    </div>
{% endblock %}
