{% extends "admin/login.html" %}
{% load i18n static two_factor_tags %}

{% block extrastyle %}
    {# Super block already includes {{ form.media }} #}
    {{ block.super }}
    <link rel="stylesheet" href="{% static "maykin_2fa/css/fixes.css" %}">
{% endblock %}

{# Overridden to render django-two-factor-auth's forms #}
{% block content %}

    {% if wizard.form.errors and not wizard.form.non_field_errors %}
        <p class="errornote">
            {% blocktranslate count counter=wizard.form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktranslate %}
        </p>
    {% endif %}

    {% if wizard.form.non_field_errors %}
        {% for error in wizard.form.non_field_errors %}
            <p class="errornote">
                {{ error }}
            </p>
        {% endfor %}
    {% endif %}

    <div id="content-main">

        {% if user.is_authenticated %}
            <p class="errornote">
                {% blocktranslate trimmed with username=request.user.get_username %}
                    You are authenticated as {{ username }}, but are not authorized to
                    access this page. Would you like to login to a different account?
                {% endblocktranslate %}
            </p>
        {% endif %}

        {% if wizard.steps.current == 'token' %}
            {% if device.method == 'call' %}
                <p>{% blocktrans trimmed %}We are calling your phone right now, please enter the
                digits you hear.{% endblocktrans %}</p>
            {% elif device.method == 'sms' %}
                <p>{% blocktrans trimmed %}We sent you a text message, please enter the tokens we
                sent.{% endblocktrans %}</p>
            {% else %}
                <p>{% blocktrans trimmed %}Please enter the tokens generated by your token
                generator.{% endblocktrans %}</p>
            {% endif %}
        {% elif wizard.steps.current == 'backup' %}
            <p>{% blocktrans trimmed %}Use this form for entering backup tokens for logging in.
            These tokens have been generated for you to print and keep safe. Please
            enter one of these backup tokens to login to your account.{% endblocktrans %}</p>
        {% endif %}

        <form action="{{ app_path }}" method="post" id="login-form" novalidate>
            {% csrf_token %}

            {% if wizard.steps.current == 'auth' %}
                {{ wizard.management_form }}

                <div class="form-row">
                    {{ form.username.errors }}
                    {{ form.username.label_tag }}
                    {{ form.username }}
                </div>

                <div class="form-row">
                    {{ form.password.errors }}
                    {{ form.password.label_tag }}
                    {{ form.password }}
                    <input type="hidden" name="next" value="{{ next }}">
                </div>

            {% else %}
                {% include "maykin_2fa/includes/wizard_form.html" %}
            {% endif %}

            {% url 'admin_password_reset' as password_reset_url %}
            {% if password_reset_url and wizard.steps.current == 'auth' %}
                <div class="password-reset-link">
                    <a href="{{ password_reset_url }}">{% translate 'Forgotten your password or username?' %}</a>
                </div>
            {% endif %}

            {# hidden submit button to enable [enter] key, otherwise the 'back' button is used #}
            <input type="submit" value="" hidden />

            <div class="submit-row">
                {% include "maykin_2fa/includes/wizard_actions.html" %}
            </div>

        </form>

        {# Can be used by downstream projects to add SSO options etc. #}
        {% block extra_login_options %}{% endblock %}

    </div>

{% endblock %}
