fix
This commit is contained in:
@@ -102,28 +102,70 @@ button:hover {
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<h2>Reset Password</h2>
|
||||
|
||||
<form>
|
||||
|
||||
<form id="resetForm">
|
||||
<div class="form-group">
|
||||
<label for="newPassword">New Password</label>
|
||||
<input id="newPassword" type="password" placeholder="New password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
|
||||
<label for="new_password">New Password</label>
|
||||
<input id="new_password" type="password" placeholder="New password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirmPassword">Confirm Password</label>
|
||||
<input id="confirmPassword" type="password" placeholder="Confirm password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
|
||||
<label for="confirm_password">Confirm Password</label>
|
||||
<input id="confirm_password" type="password" placeholder="Confirm password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
|
||||
</div>
|
||||
|
||||
<button type="submit">Reset Password</button>
|
||||
|
||||
<button type="button" onclick="resetPassword()">Reset Password</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function resetPassword() {
|
||||
const new_password = document.getElementById("new_password").value;
|
||||
const confirm_password = document.getElementById("confirm_password").value;
|
||||
|
||||
if (new_password !== confirm_password) {
|
||||
alert("Passwords do not match");
|
||||
return;
|
||||
}
|
||||
|
||||
sha256ToBase64(new_password).then((hash) => {
|
||||
const data = {
|
||||
new_password: hash,
|
||||
reset_token: "{{.ResetToken}}",
|
||||
};
|
||||
|
||||
fetch('{{.ResetPasswordLink}}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
console.log('Password reset successful');
|
||||
// 在这里执行其他成功处理逻辑
|
||||
} else {
|
||||
console.error('Password reset failed');
|
||||
// 在这里执行其他失败处理逻辑
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
// 在这里处理其他错误情况
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function sha256ToBase64(message) {
|
||||
const msgBuffer = new TextEncoder().encode(message);
|
||||
|
||||
return crypto.subtle.digest('SHA-256', msgBuffer).then((hashBuffer) => {
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
const hashBase64 = btoa(hashArray.reduce((str, byte) => str + String.fromCharCode(byte), ''));
|
||||
|
||||
return hashBase64;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user