238 lines
8.4 KiB
HTML
Executable File
238 lines
8.4 KiB
HTML
Executable File
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>找回密码</title>
|
||
<link rel="stylesheet" href="https://file.guimiaokeji.com/layui/css/layui.css">
|
||
<style>
|
||
body {
|
||
background: linear-gradient(to right, #1e3c72, #2a5298);
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
height: 100vh;
|
||
margin: 0;
|
||
font-family: 'Arial', sans-serif;
|
||
color: #fff;
|
||
}
|
||
.container {
|
||
background: rgba(255, 255, 255, 0.1);
|
||
padding: 30px;
|
||
border-radius: 10px;
|
||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
||
width: 90%;
|
||
max-width: 400px;
|
||
animation: fadeIn 1s ease-in-out;
|
||
backdrop-filter: blur(10px);
|
||
}
|
||
.layui-form-item {
|
||
margin-bottom: 20px;
|
||
}
|
||
.layui-btn {
|
||
width: 100%;
|
||
}
|
||
.input-with-button {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
.input-with-button input {
|
||
flex: 3;
|
||
}
|
||
.input-with-button button {
|
||
flex: 1;
|
||
margin-left: 10px;
|
||
padding: 9px 12px;
|
||
}
|
||
@keyframes fadeIn {
|
||
from {
|
||
opacity: 0;
|
||
transform: translateY(-20px);
|
||
}
|
||
to {
|
||
opacity: 1;
|
||
transform: translateY(0);
|
||
}
|
||
}
|
||
input::-webkit-input-placeholder {
|
||
color: rgba(255, 255, 255, 0.7);
|
||
}
|
||
input:-ms-input-placeholder {
|
||
color: rgba(255, 255, 255, 0.7);
|
||
}
|
||
input::-ms-input-placeholder {
|
||
color: rgba(255, 255, 255, 0.7);
|
||
}
|
||
input::placeholder {
|
||
color: rgba(255, 255, 255, 0.7);
|
||
}
|
||
.layui-form-item .layui-input {
|
||
background: rgba(255, 255, 255, 0.2);
|
||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||
color: #fff;
|
||
}
|
||
.layui-form-item .layui-input:focus {
|
||
border-color: #3b82ec;
|
||
}
|
||
.layui-form-label {
|
||
color: #fff;
|
||
}
|
||
.loading-spinner {
|
||
display: none;
|
||
border: 4px solid rgba(0, 0, 0, 0.1);
|
||
border-radius: 50%;
|
||
border-top: 4px solid #fff;
|
||
width: 40px;
|
||
height: 40px;
|
||
animation: spin 1s linear infinite;
|
||
position: absolute;
|
||
top: 50%;
|
||
left: 50%;
|
||
transform: translate(-50%, -50%);
|
||
}
|
||
@keyframes spin {
|
||
0% { transform: rotate(0deg); }
|
||
100% { transform: rotate(360deg); }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<div class="loading-spinner" id="loadingSpinner"></div>
|
||
<form class="layui-form" id="resetPasswordForm">
|
||
{% csrf_token %}
|
||
<div class="layui-form-item">
|
||
<label class="layui-form-label">手机号或邮箱</label>
|
||
<div class="layui-input-block input-with-button">
|
||
<input type="text" name="contact" required lay-verify="required" placeholder="手机号或邮箱" class="layui-input">
|
||
<button type="button" class="layui-btn layui-btn-normal" style="line-height: 10px;" id="sendCodeButton">发送验证码</button>
|
||
</div>
|
||
</div>
|
||
<div class="layui-form-item">
|
||
<label class="layui-form-label">验证码</label>
|
||
<div class="layui-input-block">
|
||
<input type="text" name="code" required lay-verify="required" placeholder="验证码" class="layui-input">
|
||
</div>
|
||
</div>
|
||
<div class="layui-form-item">
|
||
<label class="layui-form-label">新密码</label>
|
||
<div class="layui-input-block">
|
||
<input type="password" name="new_password" required lay-verify="required" placeholder="新密码" class="layui-input">
|
||
</div>
|
||
</div>
|
||
<div class="layui-form-item">
|
||
<label class="layui-form-label">确认密码</label>
|
||
<div class="layui-input-block">
|
||
<input type="password" name="confirm_password" required lay-verify="required" placeholder="确认密码" class="layui-input">
|
||
</div>
|
||
</div>
|
||
<div class="layui-form-item">
|
||
<button class="layui-btn" type="button" id="resetPasswordButton">重置密码</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
<script src="https://file.guimiaokeji.com/layui/jquery-3.6.0.min.js"></script>
|
||
<script src="https://file.guimiaokeji.com/layui/layui.js"></script>
|
||
<script>
|
||
layui.use(['form', 'layer'], function() {
|
||
var form = layui.form;
|
||
var $ = layui.jquery;
|
||
var layer = layui.layer;
|
||
|
||
// 显示加载动画
|
||
function showLoading() {
|
||
$('#loadingSpinner').show();
|
||
}
|
||
|
||
// 隐藏加载动画
|
||
function hideLoading() {
|
||
$('#loadingSpinner').hide();
|
||
}
|
||
|
||
// 验证密码强度
|
||
function validatePasswordStrength(password) {
|
||
var minLength = 6;
|
||
var hasNumber = /\d/;
|
||
var hasLetter = /[a-zA-Z]/;
|
||
return password.length >= minLength && hasNumber.test(password) && hasLetter.test(password);
|
||
}
|
||
|
||
// 发送验证码逻辑
|
||
$('#sendCodeButton').on('click', function() {
|
||
var contact = $('input[name="contact"]').val();
|
||
if (!contact) {
|
||
layer.msg('请输入正确的手机号或邮箱');
|
||
return;
|
||
}
|
||
showLoading();
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: '/api/send-verification-code/',
|
||
contentType: 'application/json',
|
||
data: JSON.stringify({contact: contact}),
|
||
success: function(response) {
|
||
hideLoading();
|
||
console.log("验证码发送成功", response);
|
||
layer.msg('验证码发送成功');
|
||
},
|
||
error: function(xhr, status, error) {
|
||
hideLoading();
|
||
console.error("验证码发送失败", error);
|
||
layer.msg('验证码发送失败');
|
||
}
|
||
});
|
||
});
|
||
|
||
// 重置密码逻辑
|
||
$('#resetPasswordButton').on('click', function() {
|
||
var resetData = {
|
||
contact: $('input[name="contact"]').val(),
|
||
code: $('input[name="code"]').val(),
|
||
new_password: $('input[name="new_password"]').val(),
|
||
confirm_password: $('input[name="confirm_password"]').val()
|
||
};
|
||
|
||
if (!resetData.contact || !resetData.code || !resetData.new_password || !resetData.confirm_password) {
|
||
layer.msg('请填写所有必填字段');
|
||
return;
|
||
}
|
||
|
||
if (resetData.new_password !== resetData.confirm_password) {
|
||
layer.msg('两次密码输入不一致');
|
||
return;
|
||
}
|
||
|
||
if (!validatePasswordStrength(resetData.new_password)) {
|
||
layer.msg('密码必须至少6位,并且包含数字和字母');
|
||
return;
|
||
}
|
||
|
||
showLoading();
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: '/api/reset-password/',
|
||
contentType: 'application/json',
|
||
data: JSON.stringify(resetData),
|
||
success: function(response) {
|
||
hideLoading();
|
||
console.log("密码重置成功", response);
|
||
if (response.code === 200) {
|
||
layer.msg('密码重置成功', function() {
|
||
window.location.href = '/';
|
||
});
|
||
} else {
|
||
layer.msg(response.message);
|
||
console.error("密码重置失败", response.message);
|
||
}
|
||
},
|
||
error: function(xhr, status, error) {
|
||
hideLoading();
|
||
console.error("密码重置失败", error);
|
||
layer.msg('密码重置失败', error);
|
||
}
|
||
});
|
||
});
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|