{% extends 'base.html' %}
{% block title %} | {% if token_fail %}Bad token{% else %}Set new password{% endif %}{% endblock %}

{% block main %}
<div class="page-header">
    <div class="container">
        <h1>{% if token_fail %}Bad token{% else %}Set new password{% endif %}</h1>
    </div>
</div>

<div class="container">
    {% include 'snippets/messages.html' %}

    {% if token_fail %}
        <div class="alert alert-danger">
            <p>The password reset link was invalid, possibly because it has already been used. Please request a <a href="{% url 'account_reset_password' %}">new password reset</a>.</p>
        </div>
    {% else %}
        <div class="row">
            <div class="col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
                {% if form.errors %}
                    <div class="alert alert-danger">
                        <p>An error occurred. Please try again.</p>
                    </div>
                {% endif %}

                <form action="." method="POST" novalidate>
                    {% csrf_token %}

                    <div class="form-group {% if form.password1.errors %}has-error{% endif %}">
                        <label for="password1">New password</label>
                        <input type="password" class="form-control input-lg" id="password1" name="password1" value="{{ form.data.password1 }}" required />
                        {% if form.password1.errors %}<span class="help-block">{{ form.password1.errors|striptags }}</span>{% endif %}
                    </div>

                    <div class="form-group {% if form.password2.errors or form.non_field_errors %}has-error{% endif %}">
                        <label for="password2">Repeat new password</label>
                        <input type="password" class="form-control input-lg" id="password2" name="password2" value="{{ form.data.password2 }}" required />
                        {% if form.password2.errors %}<span class="help-block">{{ form.password2.errors|striptags }}</span>{% endif %}
                        {% if form.non_field_errors %}<span class="help-block">{{ form.non_field_errors|striptags }}</span>{% endif %}
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-lg btn-primary">Change my password</button>
                    </div>
                </form>
            </div>
        </div>
    {% endif %}
</div>
{% endblock %}

{% block libraries %}
<script src="/static/js/admin.ui.forms.validate.js"></script>
{% endblock %}
