{% extends "otree/BaseAdmin.html" %}
{% load i18n otree otree_internal %}
{% block title %}Admin Login{% endblock %}

{% block content %}
    {% if form.errors and not form.non_field_errors %}
        <p class="errornote">
            Please correct the error(s).
        </p>
    {% endif %}

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

    {% if form.errors %}
        <p class="text-danger">
            If you already set a password but want to change it,
            first you may need to reset the database.
        </p>
    {% endif %}

    <p class="text-danger">{% ensure_superuser_exists %}</p>

    <div id="content-main">
        <form action="" method="post"
              id="login-form">{% csrf_token %}
                <div class="form-row">
                    {% formfield form.username %}
                </div>
                <div class="form-row">
                    {% formfield form.password %}
                    <input type="hidden" name="next" value="{{ next }}"/>
                </div>
                <p>
                    The password is defined in your <code>settings.py</code>
                    file.
                </p>

                {% 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">
                    <button type="submit" id="btn-login"
                            class="btn btn-secondary">{% trans 'Log in' %}</button>
                </div>
        </form>

        <script type="text/javascript">
            document.getElementById('id_username').focus()
        </script>
    </div>
{% endblock %}
