{% extends "base.html" %}
{% load request_static %}

{% block login_body_content %}
    <p class="login-box-msg">{% translate_text "sign in to start your session" capfirst %}
        {% block session_message_suffix %}
        {% if registration_enabled %}
        {% translate_text "or" %} <a href="{% url 'user_registration' %}">{% translate_text "sign up" %}</a>.
        {% endif %}
        {% endblock %}</p>

        {% if wait_confirmation %}
            <div class="warning">{% translate_text "confirm your email before logging in" capfirst %}</div>
            <br>
        {% endif %}
    <form method="post" action="{% url 'login' %}" class="app-form-signin form-signin" id="login_form">
        {% csrf_token %}
        {% block auth_key %}
        <div class="form-group has-feedback">
            <input type="text"
                class="form-control"
                placeholder="{% translate_text "username" capfirst %}"
                name='{{ form.username.name }}'
                id="{{ form.username.name }}"
                maxlength="254"
                autocomplete="username"
                required autofocus>
        </div>
        {% endblock %}
        <div class="form-group has-feedback">
            <input type="password"
                class="form-control"
                placeholder="{% translate_text "password" capfirst %}"
                name='{{ form.password.name }}'
                id="{{ form.password.name }}"
                autocomplete="current-password">
        </div>

        {% block button %}
            <div class="row">
                <div class="col-xs-4">
                    <button type="submit" class="btn btn-primary btn-block" style="margin-bottom: 5px" id="login_button">{% translate_text "sign in" title %}</button>
                    {% block additional_link %}
                        <a style="margin-bottom: 10px" href="{% url 'password_reset' %}">{% translate_text "forgot password" title %}?</a>
                    {% endblock %}
                </div>
            </div>
        {% endblock %}
        <input id="next" type="hidden" name="next" value="{{ next }}" />
        {% if form.errors %}
            {% translate_errors form.non_field_errors %}
        {% endif %}
    </form>
    <script>
        // Set form field next to current url for ?next= redirects
        var match = /next=(?<next>[^&]+)/.exec(window.location.href);
        if (match && match.groups.next) {
            document.getElementById('next').value = match.groups.next
        }

    </script>
{% endblock %}
