{% extends base %}
{% from 'macro.html' import breadcrumbs with context %}

{% block extrahead %}
    {{- super() }}
    <link rel="canonical" href="{{ url_for('auth.login', _external=True) }}" />
{% endblock %}

{% block content %}
<div class="row login-page">
    <div class="span12">
        {{- breadcrumbs() }}
    </div>

    {% if current_user.is_authenticated %}
        <div class="span12 login-text">
            Что такое, {{ current_user.username }}? Вы же уже авторизованы.
            Впрочем, всегда можно <a href="{{ url_for('auth.logout') }}">выйти</a>.
        </div>
    {% else %}
    <div class="span12 login-text">
        <h1>Парадный вход в библиотеку</h1>
            <form action="" method="POST" enctype="multipart/form-data" class="form-horizontal registration-form" data-noajax="1">
            <fieldset>
                {% for field in form %}
                    {% if field.widget.input_type == 'hidden' %}{{ field }}{% else %}
                    <div class="control-group{% if field.errors %} error{% endif %}">
                        <label class="control-label">{{ field.label.text }}</label>
                        <div class="controls">
                            {{ field }}
                            {% if field.errors %}
                                <p class="help-inline">
                                {% for error in field.errors %}
                                    {{ error }}
                                {% endfor %}
                                </p>
                            {% else %}
                                <p class="help-inline small">{{ field.description }}</p>
                            {% endif %}
                        </div>
                    </div>
                {% endif %}{% endfor %}
                {% with messages = get_flashed_messages() %}
                    {% for message in messages %}
                        <div class="control-group error"><p class="help-inline">{{ message }}</p></div>
                    {% endfor %}
                {% endwith %}
                <div class="control-group">
                    <div class="controls">
                        <a href="{{ url_for('auth.password_reset') }}">Забыл пароль</a><br/>
                    </div>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <button class="btn btn-primary" type="submit">Войти</button>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>
    {% endif %}
    <div class="span12">
        {{- breadcrumbs() }}
    </div>
</div>
{% endblock %}
