Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

Unsubscribe page

lotk7379860538ee
diff --git a/core/public/html/unsubscribe.html b/core/public/html/unsubscribe.html
index e6a10efc..e3de5889 100644
--- a/core/public/html/unsubscribe.html
+++ b/core/public/html/unsubscribe.html
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Unsubscribe</title>
<style>
body {
@@ -35,12 +35,12 @@
margin: 15px 0;
font-size: 16px;
}
- input[type="checkbox"] {
+ input[type='checkbox'] {
margin-right: 10px;
width: 18px;
height: 18px;
border-radius: 50%;
- accent-color:#20a53a;
+ accent-color: #20a53a;
}
button {
padding: 12px 0px;
@@ -87,40 +87,39 @@
</style>
</head>
<body>
- <div id="loading" class="loading">
- <div class="spinner"></div>
- <p>Loading...</p>
- </div>
- <div id="success-message" class="loading">
- <div class="icon">✔️</div>
- <p id="tips_success"></p>
- </div>
- <div id="error-message" class="loading">
- <div class="icon">❌</div>
- <p id="tips_error"></p>
- </div>
- <div class="unsubscribe-container" id="container">
- <h2>Are you sure to unsubscribe?</h2>
- <div class="options" id="reasonOptions">
- <label><input type="checkbox" id="selectAll">Select All</label>
- </div>
- <button onclick="confirmUnsubscribe()">Sure</button>
+<div id="loading" class="loading">
+ <div class="spinner"></div>
+ <p>Loading...</p>
+</div>
+<div id="success-message" class="loading">
+ <div class="icon">✔️</div>
+ <p id="tips_success"></p>
+</div>
+<div id="error-message" class="loading">
+ <div class="icon">❌</div>
+ <p id="tips_error"></p>
+</div>
+<div class="unsubscribe-container" id="container">
+ <h2>Are you sure to unsubscribe?</h2>
+ <div class="options" id="reasonOptions">
+ <label><input type="checkbox" id="selectAll" />Select All</label>
</div>
+ <button onclick="confirmUnsubscribe()">Sure</button>
+</div>
<script>
-
function showSuccess(value) {
const successBox = document.getElementById('success-message');
const containerBox = document.getElementById('container');
- const tips = document.getElementById('tips_success')
- tips.textContent = value
+ const tips = document.getElementById('tips_success');
+ tips.textContent = value;
containerBox.style.display = 'none';
successBox.style.display = 'flex';
}
function showError(value) {
const errorBox = document.getElementById('error-message');
- const tips = document.getElementById('tips_error')
- tips.textContent = value
+ const tips = document.getElementById('tips_error');
+ tips.textContent = value;
errorBox.style.display = 'flex';
setTimeout(() => {
errorBox.style.display = 'none';
@@ -132,18 +131,17 @@
const queryString = window.location.search.substring(1);
const regex = /([^&=]+)=([^&]*)/g;
let m;
- while (m = regex.exec(queryString)) {
+ while ((m = regex.exec(queryString))) {
params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
return params;
}
var params;
- window.onload = function() {
+ window.onload = function () {
params = getQueryParams();
- requestType({email:this.params.email});
- }
-
+ requestType({ email: this.params.email });
+ };
function renderType(data) {
const reasonOptionsDiv = document.getElementById('reasonOptions');
@@ -154,7 +152,7 @@
checkbox.name = 'reason';
checkbox.value = reason.id;
label.appendChild(checkbox);
- label.appendChild(document.createTextNode(reason.mail_type));
+ label.appendChild(document.createTextNode(reason.name));
reasonOptionsDiv.appendChild(label);
});
@@ -173,75 +171,74 @@
});
}
-
function requestType(reqData) {
document.getElementById('loading').style.display = 'flex';
+
fetch(params.url_type, {
method: 'POST',
headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
+ 'Content-Type': 'application/json',
},
- body: new URLSearchParams(reqData).toString()
- })
- .then(response => response.json())
- .then(data => {
- if (data.status){
- this.renderType(data.msg);
- }else{
- this.showError(data.msg)
- }
- })
- .catch((err) => {
- this.showError(err)
+ body: JSON.stringify(reqData),
})
- .finally(() => {
- document.getElementById('loading').style.display = 'none';
- });
+ .then(response => {
+ return response.json();
+ })
+ .then(data => {
+ if (data.success) {
+ this.renderType(data.data);
+ } else {
+ this.showError(data.msg);
+ }
+ })
+ .catch(err => {
+ this.showError(err);
+ })
+ .finally(() => {
+ document.getElementById('loading').style.display = 'none';
+ });
}
-
function requestApi(value) {
document.getElementById('loading').style.display = 'flex';
const data = {
jwt: params.jwt,
- id: value
+ group_id: value,
};
fetch(params.url_unsubscribe, {
method: 'POST',
headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
+ 'Content-Type': 'application/json',
},
- body: new URLSearchParams(data).toString()
- })
- .then(response => {
- if (!response.ok) {
- throw new Error('Network response was not ok');
- }
- return response.json();
+ body: JSON.stringify(data),
})
- .then((res) => {
- if(res.status){
- this.showSuccess(res.msg)
- }else{
- this.showError(res.msg)
- }
- })
- .catch((err) => {
- this.showError(err)
- })
- .finally(() => {
- document.getElementById('loading').style.display = 'none';
- });
+ .then(response => {
+ if (!response.ok) {
+ throw new Error('Network response was not ok');
+ }
+ return response.json();
+ })
+ .then(res => {
+ if (res.success) {
+ this.showSuccess(res.msg);
+ } else {
+ this.showError(res.msg);
+ }
+ })
+ .catch(err => {
+ this.showError(err);
+ })
+ .finally(() => {
+ document.getElementById('loading').style.display = 'none';
+ });
}
// 确认取消事件
function confirmUnsubscribe() {
- const selectedReasons = Array.from(document.querySelectorAll('input[name="reason"]:checked'))
- .map(checkbox => checkbox.value)
- .join(',');
- if (!selectedReasons) {
- this.showError('Please select at least one')
+ const selectedReasons = Array.from(document.querySelectorAll('input[name="reason"]:checked')).map(checkbox => checkbox.value);
+ if (selectedReasons.length === 0) {
+ this.showError('Please select at least one');
return;
}
requestApi(selectedReasons);