feat(email): allow unsub via POST request

This commit is contained in:
Sabe Jones
2024-02-07 16:09:23 -06:00
parent 67a6e6f8ac
commit 91795875b5

View File

@@ -7,26 +7,7 @@ import {
const api = {};
/**
* @api {get} /email/unsubscribe Unsubscribe an email address or user from email notifications
* @apiName UnsubscribeEmail
* @apiGroup Unsubscribe
* @apiDescription This is a GET method included in official emails from Habitica
* that will unsubscribe the user from emails.
* Does not require authentication.
*
* @apiParam (Query) {String} code An unsubscription code that contains an encrypted User ID or
* email address
*
* @apiSuccess {String} Webpage An html success message
*
* @apiError (400) {BadRequest} missingUnsubscriptionCode The unsubscription code is missing.
* @apiUse UserNotFound
*/
api.unsubscribe = {
method: 'GET',
url: '/email/unsubscribe',
async handler (req, res) {
async function emailUnsubscribe (req, res) {
req.checkQuery({
code: {
notEmpty: { errorMessage: res.t('missingUnsubscriptionCode') },
@@ -54,6 +35,54 @@ api.unsubscribe = {
const okResponse = `<h1>${res.t('unsubscribedSuccessfully')}</h1> ${res.t('unsubscribedTextOthers')}`;
res.send(okResponse);
}
}
/**
* @api {get} /email/unsubscribe Unsubscribe an email address or user from email notifications
* @apiName UnsubscribeEmail
* @apiGroup Unsubscribe
* @apiDescription This is a GET method included in official emails from Habitica
* that will unsubscribe the user from emails.
* Does not require authentication.
*
* @apiParam (Query) {String} code An unsubscription code that contains an encrypted User ID or
* email address
*
* @apiSuccess {String} Webpage An html success message
*
* @apiError (400) {BadRequest} missingUnsubscriptionCode The unsubscription code is missing.
* @apiUse UserNotFound
*/
api.unsubscribe = {
method: 'GET',
url: '/email/unsubscribe',
async handler (req, res) {
await emailUnsubscribe(req, res);
},
};
/**
* @api {post} /email/unsubscribe Unsubscribe an email address or user from email notifications
* @apiName OneClickUnsubscribe
* @apiGroup Unsubscribe
* @apiDescription This is a POST method for compliance with RFC 8058. It works identically to the
* GET method on the same URI, allowing the user to unsubscribe from emails either via visiting a
* hyperlink or activating a one-click Unsubscribe button in their email client.
* Does not require authentication.
*
* @apiParam (Query) {String} code An unsubscription code that contains an encrypted User ID or
* email address
*
* @apiSuccess {String} Webpage An html success message
*
* @apiError (400) {BadRequest} missingUnsubscriptionCode The unsubscription code is missing.
* @apiUse UserNotFound
*/
api.oneClickUnsubscribe = {
method: 'POST',
url: '/email/unsubscribe',
async handler (req, res) {
await emailUnsubscribe(req, res);
},
};