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

{% block title %}{% trans "Password Reset" %}{% endblock %}

{% block extra_style %}{{block.super}}
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/seahub.css" />
<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 %}

{% if validlink %}

<div class="new-narrow-panel">
    <h2 class="hd">{% trans "Reset Password" %}</h2>
    <form action="" method="post" class="con" id="signup-form">{% csrf_token %}
        <label for="id_new_password1">{% trans "New Password: " %}</label>
        <div class="position-relative" id="password-input1">
            {{ form.new_password1 }}
        </div>
        <label for="id_new_password2">{% trans "Confirm Password: " %}</label>
        <div class="position-relative" id="password-input2">
            {{ form.new_password2 }}
        </div>
        <p class="error hide"></p>
        <input type="submit" value="{% trans "Submit" %}" class="submit" />
    </form>
</div>

{% else %}

<div class="text-panel">
    <p>{% trans "Failed to reset password: this link is no longer available." %}</p>
</div>

{% endif %}
{% 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="password"]').addClass('input');
{% include "snippets/password_strength_js.html" %}
$(function () {
    setupPasswordField("id_new_password1", passwd_tip, template);
});

$('#signup-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 %}
