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">
|
<script th:if="${globalInfo.mustVerifyEmailOnRegistration}" th:inline="javascript">
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
function sendRequest() {
|
const headerName = /*[[${_csrf.headerName}]]*/ "";
|
||||||
return new Promise((resolve, reject) => {
|
const token = /*[[${_csrf.token}]]*/ "";
|
||||||
const email = document.getElementById("email").value;
|
async function sendRequest() {
|
||||||
|
const email = document.getElementById("email").value;
|
||||||
|
|
||||||
if (!email) {
|
if (!email) {
|
||||||
throw new Error(/*[[#{form.emailCode.send.emptyValidation}]]*/"");
|
throw new Error(/*[[#{form.emailCode.send.emptyValidation}]]*/ "");
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch("/signup/send-email-code", {
|
const response = await fetch("/signup/send-email-code", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({ email: email }),
|
body: JSON.stringify({ email: email }),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
[[${_csrf.headerName}]]: [[${_csrf.token}]],
|
[headerName]: token,
|
||||||
},
|
},
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
if (response.ok) {
|
|
||||||
resolve(response);
|
|
||||||
}
|
|
||||||
reject(response);
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
reject(e);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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");
|
const emailCodeSendButton = document.getElementById("emailCodeSendButton");
|
||||||
|
|
Loading…
Reference in New Issue