mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
v3: misc fixes
This commit is contained in:
@@ -229,7 +229,6 @@ function _passportFbProfile (accessToken) {
|
||||
}
|
||||
|
||||
// Called as a callback by Facebook (or other social providers). Internal route
|
||||
// TODO move to top-level/auth?
|
||||
api.loginSocial = {
|
||||
method: 'POST',
|
||||
url: '/user/auth/social', // this isn't the most appropriate url but must be the same as v2
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import { model as User } from '../../models/user';
|
||||
import { model as EmailUnsubscription } from '../../models/emailUnsubscription';
|
||||
import { decrypt } from '../../libs/api-v3/encryption';
|
||||
import {
|
||||
NotFound,
|
||||
} from '../../libs/api-v3/errors';
|
||||
|
||||
let api = {};
|
||||
|
||||
// TODO move to top-level controllers?
|
||||
/**
|
||||
* @api {get} /api/v3/email/unsubscribe Unsubscribe an email or user from email notifications
|
||||
* @apiDescription Does not require authentication
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName UnsubscribeEmail
|
||||
* @apiGroup Unsubscribe
|
||||
* @apiDescription This is a GET method so that you can put the unsubscribe link in emails.
|
||||
*
|
||||
* @apiParam {String} code Query parameter - An unsubscription code
|
||||
*
|
||||
* @apiSuccess {String} An html success message
|
||||
*/
|
||||
api.unsubscribe = {
|
||||
method: 'GET',
|
||||
url: '/email/unsubscribe',
|
||||
async handler (req, res) {
|
||||
req.checkQuery({
|
||||
code: {
|
||||
notEmpty: {errorMessage: res.t('missingUnsubscriptionCode')},
|
||||
},
|
||||
});
|
||||
let validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
let data = JSON.parse(decrypt(req.query.code));
|
||||
|
||||
if (data._id) {
|
||||
let userUpdated = await User.update(
|
||||
{_id: data._id},
|
||||
{ $set: {'preferences.emailNotifications.unsubscribeFromAll': true}}
|
||||
);
|
||||
|
||||
if (userUpdated.nModified !== 1) throw new NotFound(res.t('userNotFound'));
|
||||
|
||||
res.send(`<h1>${res.t('unsubscribedSuccessfully')}</h1> ${res.t('unsubscribedTextUsers')}`);
|
||||
} else {
|
||||
let unsubscribedEmail = await EmailUnsubscription.findOne({email: data.email.toLowerCase()});
|
||||
let okResponse = `<h1>${res.t('unsubscribedSuccessfully')}</h1> ${res.t('unsubscribedTextOthers')}`;
|
||||
if (!unsubscribedEmail) await EmailUnsubscription.create({email: data.email.toLowerCase()});
|
||||
res.send(okResponse);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = api;
|
||||
@@ -760,7 +760,6 @@ api.removeTagFromTask = {
|
||||
},
|
||||
};
|
||||
|
||||
// TODO this method needs some limitation, like to check if the challenge is really broken?
|
||||
/**
|
||||
* @api {post} /api/v3/tasks/unlink/:taskId Unlink a challenge task
|
||||
* @apiVersion 3.0.0
|
||||
@@ -793,6 +792,7 @@ api.unlinkTask = {
|
||||
|
||||
if (!task) throw new NotFound(res.t('taskNotFound'));
|
||||
if (!task.challenge.id) throw new BadRequest(res.t('cantOnlyUnlinkChalTask'));
|
||||
if (!task.challenge.broken) throw new BadRequest(res.t('cantOnlyUnlinkChalTask'));
|
||||
|
||||
if (keep === 'keep') {
|
||||
task.challenge = {};
|
||||
|
||||
Reference in New Issue
Block a user