<!-- templates/users/change_password.html -->
{% extends "users/center/index.html" %}
{% load static %}

{% block title %}修改密码 - 用户中心{% endblock %}

{% block user_center_right %}

    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title mb-0">修改密码</h4>
                </div>
                <div class="card-body">
                    
                    
                    <form id="changePasswordForm" method="post">
                        {% csrf_token %}
                        
                        <div class="mb-3">
                            <label for="old_password" class="form-label">当前密码</label>
                            <input type="password" class="form-control" id="old_password" name="old_password" 
                                   required autocomplete="current-password">
                            <div class="invalid-feedback">请输入当前密码</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="new_password1" class="form-label">新密码</label>
                            <input type="password" class="form-control" id="new_password1" name="new_password1" 
                                   required autocomplete="new-password" minlength="8">
                            <div class="form-text">密码至少8位，建议包含字母、数字和特殊字符</div>
                            <div class="invalid-feedback">请输入新密码</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="new_password2" class="form-label">确认新密码</label>
                            <input type="password" class="form-control" id="new_password2" name="new_password2" 
                                   required autocomplete="new-password" minlength="8">
                            <div class="invalid-feedback">请再次输入新密码</div>
                        </div>
                        
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">修改密码</button>
                            <a href="{% url 'users:user_index' %}" class="btn btn-secondary">返回</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block extra_scripts %}
<script>
document.getElementById('changePasswordForm').addEventListener('submit', function(e) {
    const form = e.target;
    const newPassword1 = document.getElementById('new_password1').value;
    const newPassword2 = document.getElementById('new_password2').value;
    
    // 客户端验证
    if (newPassword1 !== newPassword2) {
        e.preventDefault();
        alert('两次输入的新密码不一致！');
        return false;
    }
    
    if (newPassword1.length < 8) {
        e.preventDefault();
        alert('密码长度不能少于8位！');
        return false;
    }
    
    return true;
});
</script>
{% endblock %}