{% extends "two_column_body.html" %}
{% import "authopenid/authopenid_macros.html" as login_macros %}
{% from "macros.html" import timeago %}
<!-- signin.html -->
{% block title %}{% filter trim %}{% trans %}User login{% endtrans %}{% endfilter %}{% endblock %}
{% block forestyle %}
    <link rel="stylesheet" type="text/css" media="screen" href="{{ "/style/openid.css"|media }}"/>
{% endblock %}
{% block content %}
    {% if settings.AUTHENTICATION_PAGE_MESSAGE %}
        <div class="instructions-message">
            {{ settings.AUTHENTICATION_PAGE_MESSAGE|convert_markdown }}
        </div>
    {% endif %}
    {% if have_buttons %}
        <h1 class="section-title">{{ page_title }}</h1>
    {% endif %}
    {% if not (view_subtype == 'default' and have_buttons) %}
    <p class="js-login-intro">
        {% if view_subtype == 'add_openid' and have_buttons %}
            {% if existing_login_methods %}
                {% trans %}It's a good idea to make sure that your existing login methods still work, or add a new one. Please click any of the icons below to check/change or add new login methods.{% endtrans %}
            {% else %}
                {% trans %}Please add a more permanent login method by clicking one of the icons below, to avoid logging in via email each time.{% endtrans %}
            {% endif %}
        {% elif view_subtype == 'change_openid' and have_buttons %}
            {% if existing_login_methods %}
                {% trans %}Click on one of the icons below to add a new login method or re-validate an existing one.{% endtrans %}
            {% else %}
                {% trans %}You don't have a method to log in right now, please add one or more by clicking any of the icons below.{% endtrans %}
            {% endif %}
        {% endif %}
    </p>
    {% endif %}
    {% if openid_error_message %}
        <p class="warning">{{ openid_error_message }}</p>
    {% endif %}
    <form id="signin-form" method="post" action="{{ settings.LOGIN_URL }}">{{ csrf_input }}
        {# in this branch - the real signin view we display the login icons
            here we hide the local login button only if admin
            wants to always show the password login form - then
            the button is useless.
        #}
        {% if 'in_recovery' in request.session %}
            <input type="hidden" name="in_recovery" value="true" />
        {% endif %}
        {{ login_form.login_provider_name }}
        {{ login_form.next }}
        {{ login_form.persona_assertion }}
        {{
            login_macros.provider_buttons(
                login_form = login_form,
                major_login_providers = major_login_providers,
                minor_login_providers = minor_login_providers,
                settings = settings,
                logged_in = user.is_authenticated,
                show_buttons = have_buttons
            )
        }}
          {% if use_password_login == True %}
        <fieldset id="password-fs">
            {{login_form.password_action}}
            {% if user.is_anonymous or settings.USE_LDAP_FOR_PASSWORD_LOGIN %}
                {% if have_buttons %}
                    <h2 id="password-heading">
                        {% trans %}or enter your <span>user name and password</span>{% endtrans %}
                    </h2>
                {% else %}
                    <h1 class="section-title">
                        {% trans %}Please, sign in{% endtrans %}
                    </h1>
                {% endif %}
                <div class="login">
                    {% if login_form.password_login_failed %}
                        <p class="error">{% trans %}Login failed, please try again{% endtrans %}</p>
                    {% endif %}
                    <div class="form-group">
                        <input class="required login" id="id_username"
                            maxlength="255" name="username" type="text"
                            {% if login_form.username.value() %}
                                value="{{ login_form.username.value()|escape }}"
                            {% endif %}
                            {% if settings.USE_LDAP_FOR_PASSWORD_LOGIN %}
                                placeholder="{% trans %}Username{% endtrans %}"
                            {% else %}
                                placeholder="{% trans %}Username or email{% endtrans %}"
                            {% endif %}
                        >
                    </div>
                    <div class="form-group">
                        <input class="required login" id="id_password"
                            maxlength="128" name="password" type="password"
                            {% if login_form.password.value() %}
                                value="{{ login_form.password.value()|escape }}"
                            {% endif %}
                            placeholder="{% trans %}Password{% endtrans %}">
                    </div>
                </div>
                <p id="local_login_buttons">
                    <input class="button" name="login_with_password" type="submit" value="{% trans %}Sign in{% endtrans %}" />
                    {% if settings.USE_LDAP_FOR_PASSWORD_LOGIN == False and settings.NEW_REGISTRATIONS_DISABLED == False %}
                        <a class="create-password-account" style="vertical-align:middle" href="{{ url('user_signup_with_password') }}">{% trans %}Create a password-protected account{% endtrans %}</a>
                    {% endif %}
                </p>
            {% else %}{# change password form #}
                <h2 id="password-heading">
                    {% trans %}To change your password - please enter the new one twice, then submit{% endtrans %}
                </h2>
                <div class="login">
                    <div class="form-group js-new_password">
                        <span class="error form-error">{{login_form.new_password.errors[0]}}</span>
                        <input class="required login" id="id_new_password"
                            maxlength="128" name="new_password" type="password"
                            {% if login_form.new_password.value() %}
                                value="{{ login_form.new_password.value()|escape }}"
                            {% endif %}
                            placeholder="{% trans %}New password{% endtrans %}"
                        >
                    </div>
                    <div class="form-group js-new_password_retyped">
                        <span class="error form-error">{{login_form.new_password_retyped.errors[0]}}</span>
                        <input class="required login" id="id_new_password_retyped" maxlength="128"
                            name="new_password_retyped" type="password"
                            {% if login_form.new_password_retyped.value() %}
                                value="{{ login_form.new_password_retyped.value()|escape }}"
                            {% endif %}
                            placeholder="{% trans %}Please, retype{% endtrans %}"
                        >
                    </div>
                </div>
                <p id="local_login_buttons">
                    <input class="button" name="change_password" type="submit" value="{% trans %}Change password{% endtrans %}" />
                </p>
            {% endif %}
        </fieldset>
        {% endif %}
    </form>
    {% if user.is_authenticated and existing_login_methods and settings.ALLOW_ADD_REMOVE_LOGIN_METHODS %}
    <div
        id='existing-login-methods'
        {% if login_form.password_change_failed %}
            style="display:none";
        {% endif %}
    >
        <h2 id='ab-show-login-methods'>
            {% trans %}Here are your current login methods{% endtrans %}
        </h2>
        <table id='ab-existing-login-methods'>
            <tr>
                <th>{% trans %}provider{% endtrans %}</th>
                <th>{% trans %}last used{% endtrans %}</th>
            </tr>
            {% for login_method in existing_login_methods %}
            <tr class="ab-provider-row">
                <td class="ab-provider-name">
                    {{login_method.provider_name}}
                </td>
                <td>
                    {% if login_method.last_used_timestamp %}
                        {{ timeago(login_method.last_used_timestamp) }}
                    {% endif %}
                </td>
                <td>
                    {% if login_method.is_deletable %}
                        <button>{% trans %}delete{% endtrans %}</button>
                    {% else %}
                        {% trans %}cannot be deleted{% endtrans %}
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </table>
    </div>
    {% endif %}
    {% if user.is_anonymous and settings.ALLOW_ACCOUNT_RECOVERY_BY_EMAIL %}
        <form id="account-recovery-form" action="{{ url('user_account_recover') }}" method="post">{{ csrf_input }}
            <h2 id='account-recovery-heading'>{% trans %}Having trouble signing in?{% endtrans %}</h2>
            {% if account_recovery_form.email.errors %}
                <p class="error">{{account_recovery_form.email.errors[0]}}</p>
            {% endif %}
            <input id="id_email" name="email" type="text" placeholder="{% trans %}Enter your email{% endtrans %}">
            <input type="submit" class="button" value="{% trans %}Recover account{% endtrans %}"/>
        </form>
    {% endif %}
{% endblock %}
{% block endjs %}
{% include "authopenid/providers_javascript.html" %}
{% endblock %}
<!-- end signin.html -->
