Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
laodaming 2023-09-06 11:50:04 +08:00
commit 4895c4c417
2 changed files with 21 additions and 13 deletions

View File

@ -51,7 +51,7 @@ button {
background-color: #007bff; background-color: #007bff;
color: #fff; color: #fff;
border: none; border: none;
border-radius: 3px; border-radius: 5px;
cursor: pointer; cursor: pointer;
} }
@ -59,7 +59,6 @@ button:hover {
background-color: #0056b3; background-color: #0056b3;
} }
/* Mobile */ /* Mobile */
@media screen and (max-width: 767px) { @media screen and (max-width: 767px) {
.container { .container {
@ -102,31 +101,40 @@ button:hover {
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h2>Reset Password</h2> <h2>Reset Password</h2>
<form id="resetForm"> <form id="resetForm">
<div class="form-group"> <div class="form-group">
<label for="new_password">New Password</label> <label for="new_password">New Password</label>
<input id="new_password" type="password" placeholder="New password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$"> <input id="new_password" type="password" placeholder="New Password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$" title="The password must be at least 8 characters in length, and contain at least 1 number, 1 lowercase letter and 1 uppercase letter."/>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="confirm_password">Confirm Password</label> <label for="confirm_password">Confirm Password</label>
<input id="confirm_password" type="password" placeholder="Confirm password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$"> <input id="confirm_password" type="password" placeholder="Confirm Password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$" title="The password must be at least 8 characters in length, and contain at least 1 number, 1 lowercase letter and 1 uppercase letter."/>
</div> </div>
<button type="button" onclick="resetPassword()">Reset Password</button> <button type="button" onclick="resetPassword()">Reset Password</button>
</form> </form>
</div> </div>
<script> <script>
function resetPassword() { function resetPassword() {
const new_password = document.getElementById("new_password").value; const new_password = document.getElementById("new_password").value;
const confirm_password = document.getElementById("confirm_password").value; const confirm_password = document.getElementById("confirm_password").value;
if (!/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/.test(new_password)) {
alert("The password must be at least 8 characters in length, and contain at least 1 number, 1 lowercase letter and 1 uppercase letter.");
return;
}
if (new_password !== confirm_password) { if (new_password !== confirm_password) {
alert("Passwords do not match"); alert("Passwords do not match");
return; return;
} }
sha256ToBase64(new_password).then((hash) => { sha256ToBase64(new_password).then((hash) => {
const data = { const data = {
new_password: hash, new_password: hash,
@ -143,26 +151,26 @@ function resetPassword() {
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
if (data.code == 200 ) { if (data.code == 200 ) {
alert(data.msg); alert("reset password success");
window.location.href = "{{.HomePage}}"; window.location.href = "{{.HomePage}}";
{{/* setTimeout(function() {
window.location.href = "{{.HomePage}}";
}, 1000); */}}
} else { } else {
alert(data.msg); alert(data.msg);
} }
}) })
.catch(error => { .catch(error => {
console.error('Error:', error); console.error('Error:', error);
// 在这里处理其他错误情况
}); });
}); });
} }
function sha256ToBase64(message) { function sha256ToBase64(message) {
const msgBuffer = new TextEncoder().encode(message); const msgBuffer = new TextEncoder().encode(message);
return crypto.subtle.digest('SHA-256', msgBuffer).then((hashBuffer) => { return crypto.subtle.digest('SHA-256', msgBuffer).then((hashBuffer) => {
const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashBase64 = btoa(hashArray.reduce((str, byte) => str + String.fromCharCode(byte), '')); const hashBase64 = btoa(hashArray.reduce((str, byte) => str + String.fromCharCode(byte), ''));
return hashBase64; return hashBase64;
}); });
} }

View File

@ -41,10 +41,10 @@ func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinf
return resp.SetStatus(basic.CodeOAuthEmailErr) return resp.SetStatus(basic.CodeOAuthEmailErr)
} }
_, err := l.svcCtx.AllModels.FsUser.FindUserByEmail(l.ctx, req.Email) // _, err := l.svcCtx.AllModels.FsUser.FindUserByEmail(l.ctx, req.Email)
if err == nil { // if err == nil {
return resp.SetStatus(basic.CodeEmailExistsErr) // return resp.SetStatus(basic.CodeEmailExistsErr)
} // }
if !TimeLimit.Is(req.Email) { if !TimeLimit.Is(req.Email) {
return resp.SetStatus(basic.CodeEmailTimeShortErr) return resp.SetStatus(basic.CodeEmailTimeShortErr)