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

{% block sub_title %}{% trans "Set Password" %} - {% endblock %}

{% block extra_style %}
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}bootstrap/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}bootstrap/bootstrap.popover.min.css" />
{% endblock %}

{% block main_content %}
<div class="new-narrow-panel vh">
    <h2 class="hd">{% trans "Set Password" %}</h2>
    <form action="" method="post" class="con">{% csrf_token %}

        {% if form.contact_email %}
        <label for="id_contact_email">{% trans "Contact Email" %}</label>
        {{ form.contact_email }}
        {{ form.contact_email.errors }}
        {% endif %}

        <label for="id_new_password1">{% trans "Password" %}</label><br />
        {{ form.new_password1 }}<br />    {{ form.new_password1.errors }}
        <div id="pwd_strength"></div>
        <label for="id_new_password2">{% trans "Confirm Password" %}</label><br />
        {{ form.new_password2 }}<br />    {{ form.new_password2.errors }}
        <p class="error hide"></p>
        <input type="submit" value="{% trans "Submit" %}" class="submit" />
    </form>
</div>
{% endblock %}

{% block extra_script %}
<script type="text/javascript" src="{{MEDIA_URL}}bootstrap/bootstrap.popover.min.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}bootstrap/bootstrap.min.js"></script>
<script type="text/javascript">
$('[type="email"], [type="password"]').addClass('input');
$('.new-narrow-panel').removeClass('vh');

{% include "snippets/password_strength_js.html" %}

$(function () {
    setupPasswordField("id_new_password1", passwd_tip, template);
});

$('form').on('submit', function(){
    var pwd1 = $('input[name="new_password1"]').val().trim(),
        pwd2 = $('input[name="new_password2"]').val().trim();

    if (!pwd1) {
        $('.error').html("{% trans "Password cannot be blank" %}").removeClass('hide');
        return false;
    }
    if (!pwd2) {
        $('.error').html("{% trans "Please enter the password again" %}").removeClass('hide');
        return false;
    }
    if (pwd1 != pwd2) {
        $('.error').html("{% trans "Passwords don't match" %}").removeClass('hide');
        return false;
    }

    if (!checkPasswordStrength(pwd1, {{strong_pwd_required}})) {
        $('.error').html(passwd_tip).removeClass('hide');
        return false;
    }
});
</script>
{% endblock %}
