mirror of https://github.com/halo-dev/halo
feat: support toast a message for backend exceptions when sending emails (#6856)
#### What type of PR is this? /area core /kind improvement /milestone 2.20.x #### What this PR does / why we need it: 注册表单发送邮箱验证码时,支持显示来自后端的异常。 <img width="693" alt="image" src="https://github.com/user-attachments/assets/78d1d793-7673-4442-9b0b-1eb7c4d91ebd"> #### Does this PR introduce a user-facing change? ```release-note None ```pull/6848/head
parent
0d8c4bb126
commit
b0d36b784e
|
@ -123,32 +123,32 @@
|
|||
|
||||
<script th:if="${globalInfo.mustVerifyEmailOnRegistration}" th:inline="javascript">
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
function sendRequest() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const email = document.getElementById("email").value;
|
||||
const headerName = /*[[${_csrf.headerName}]]*/ "";
|
||||
const token = /*[[${_csrf.token}]]*/ "";
|
||||
async function sendRequest() {
|
||||
const email = document.getElementById("email").value;
|
||||
|
||||
if (!email) {
|
||||
throw new Error(/*[[#{form.emailCode.send.emptyValidation}]]*/"");
|
||||
}
|
||||
if (!email) {
|
||||
throw new Error(/*[[#{form.emailCode.send.emptyValidation}]]*/ "");
|
||||
}
|
||||
|
||||
fetch("/signup/send-email-code", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ email: email }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
[[${_csrf.headerName}]]: [[${_csrf.token}]],
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
resolve(response);
|
||||
}
|
||||
reject(response);
|
||||
})
|
||||
.catch((e) => {
|
||||
reject(e);
|
||||
});
|
||||
const response = await fetch("/signup/send-email-code", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ email: email }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
[headerName]: token,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const json = await response.json();
|
||||
if (json.errors && json.errors.length) {
|
||||
throw new Error(json.errors[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
const emailCodeSendButton = document.getElementById("emailCodeSendButton");
|
||||
|
|
Loading…
Reference in New Issue