Skip to content
Permalink
Browse files
Add ability to set do-not-email for users
  • Loading branch information
Johnny Lin committed Jun 24, 2020
1 parent 2c614e6 commit 37c49eaa97716eb8e632e187c46a521ac4a38775
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
@@ -159,6 +159,38 @@ authenticate,
.catch(error => { next(error); });
});

/*********************************************
*
* Email Opt Out User
*
*********************************************/

router.post("/set-do-not-email",
[
authenticate,
body("email")
.exists().withMessage("Missing email address.")
.isEmail().withMessage("Invalid email address.")
.normalizeEmail({
gmail_remove_dots: false
}),
validateCheck
],
(request, response, next) => {
var email = request.values.email;
// Check that we do have this email in the database
return User.getWithEmail(email)
.then(user => {
return User.setDoNotEmail(email, user.doNotEmailCode);
})
.then(success => {
response.status(200).json({
message: "Do not email set successfully."
});
})
.catch(error => { next(error); });
});

/*********************************************
*
* Delete User
@@ -80,6 +80,17 @@
</div>
</div>

<div class="col-xl-4 col-md-6 col-xs-12 text-left p-3 confirmed-bg">
<h1 class="h6 text-center"><strong>Do Not Email</strong></h1>
<div>
<input type="text" id="doNotEmailEmail" class="form-control" placeholder="test@test.com"/>
<button onclick="document.getElementById('doNotEmailEmail').value='';" class="btn confirmed-gray-btn btn-sm mt-2" style="width: 49%;">Clear</button>
<button id="doNotEmailButton" onclick="doNotEmail();" class="btn confirmed-blue-btn btn-sm mt-2" style="width: 49%;">Submit</button>
<input type="text" id="doNotEmailResult" class="form-control mt-2" placeholder="Result Appears Here" readonly="readonly"/>
</div>
</div>


</div>

<div class="col-xl-6 offset-xl-3 col-xs-12 text-left mb-5">
@@ -164,6 +175,28 @@
http.send(params);
}
}
function doNotEmail() {
document.getElementById("doNotEmailButton").disabled = true;
document.getElementById("doNotEmailResult").value = "";
var http = new XMLHttpRequest();
var url = "set-do-not-email";
http.open("POST", url, true);
var params = "email=" + document.getElementById("doNotEmailEmail").value;
http.responseType = 'json';
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if (http.readyState == 4) {
document.getElementById("doNotEmailButton").disabled = false;
if (http.status == 200) {
document.getElementById("doNotEmailResult").value = http.response.message;
return;
}
alert("Error: " + JSON.stringify(http.response));
}
}
http.send(params);
}
</script>

@@ -272,6 +272,7 @@
data: http.response.message,
columns: [
{ title: "time", field: "timestamp" },
{ title: "sender", field: "sender" },
{ title: "sendTime", field: "sendTime" },
{ title: "recipient", field: "rEmail" },
{ title: "type", field: "complaintFeedbackType" },

0 comments on commit 37c49ea

Please sign in to comment.