{% extends 'admin/login.html' %}
{% load i18n %}


{% block content %}

    {% if form.errors and not form.non_field_errors %}
        <p class="errornote">
            {% if form.errors.items|length == 1 %}{% trans "Please correct the error below." %}{% else %}
                {% trans "Please correct the errors below." %}{% endif %}
        </p>
    {% endif %}

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

    <div id="content-main">

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

        <form action="{{ app_path }}" method="post" id="login-form">{% csrf_token %}
            <div class="form-row{% if form.username.errors %} has-danger{% endif %}">
                <input type="text" name="{{ form.username.html_name }}" id="{{ form.username.id_for_label }}"
                       placeholder="{{ form.username.label }}" maxlength="254" value="{% if form.username.value %}{{ form.username.value }}{% endif %}" class="form-control form-control-lg">
                {{ form.username.errors }}
            </div>
            <div class="form-row{% if form.password.errors %} has-danger{% endif %}">
                <input type="password" name="{{ form.password.html_name }}" id="{{ form.password.id_for_label }}" placeholder="{{ form.password.label }}" class="form-control form-control-lg">
                {{ form.password.errors }}
                <input type="hidden" name="next" value="{{ next }}"/>
            </div>
            {% url 'admin_password_reset' as password_reset_url %}
            {% if password_reset_url %}
                <div class="password-reset-link">
                    <a href="{{ password_reset_url }}">{% trans 'Forgotten your password or username?' %}</a>
                </div>
            {% endif %}
            <div class="submit-row">
                <label>&nbsp;</label><input type="submit" value="{% trans 'Log in' %}"/>
            </div>
        </form>

        <script type="text/javascript">
            if(!document.getElementById('id_username').value)
                document.getElementById('id_username').focus();
            else
                document.getElementById('id_password').focus();
        </script>
    </div>
{% endblock %}
