mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
feat(email): allow unsub via POST request
This commit is contained in:
@@ -7,26 +7,7 @@ import {
|
|||||||
|
|
||||||
const api = {};
|
const api = {};
|
||||||
|
|
||||||
/**
|
async function emailUnsubscribe (req, res) {
|
||||||
* @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) {
|
|
||||||
req.checkQuery({
|
req.checkQuery({
|
||||||
code: {
|
code: {
|
||||||
notEmpty: { errorMessage: res.t('missingUnsubscriptionCode') },
|
notEmpty: { errorMessage: res.t('missingUnsubscriptionCode') },
|
||||||
@@ -54,6 +35,54 @@ api.unsubscribe = {
|
|||||||
const okResponse = `<h1>${res.t('unsubscribedSuccessfully')}</h1> ${res.t('unsubscribedTextOthers')}`;
|
const okResponse = `<h1>${res.t('unsubscribedSuccessfully')}</h1> ${res.t('unsubscribedTextOthers')}`;
|
||||||
res.send(okResponse);
|
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);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user