mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-12 17:28:42 +00:00
finalize unsubscription page
This commit is contained in:
parent
a7c789746a
commit
ab1b75b655
2 changed files with 16 additions and 10 deletions
|
|
@ -98,6 +98,9 @@
|
|||
"invitedQuest": "Invited to Quest",
|
||||
"kickedGroup": "Kicked from group",
|
||||
"remindersToLogin": "Reminders to check in to HabitRPG",
|
||||
"unsubscribedSuccessfully": "Unsubscribed successfully!",
|
||||
"unsubscribedTextUsers": "You have successfully unsubscribed from all HabitRPG emails. You can enable only the emails you want to receive from <a href=\"/#/options/settings/notifications\">the settings</a> (requires login).",
|
||||
"unsubscribedTextOthers": "You won't receive any other email from HabitRPG.",
|
||||
"unsubscribeAllEmails": "Check to Unsubscribe from Emails",
|
||||
"unsubscribeAllEmailsText": "By checking this box, I certify that I understand that by unsubscribing from all emails, HabitRPG will never be able to notify me via email about important changes to the site or my account.",
|
||||
"correctlyUnsubscribedEmailType": "Correctly unsubscribed from \"<%= emailType %>\" emails.",
|
||||
|
|
|
|||
|
|
@ -1,32 +1,35 @@
|
|||
var User = require('../models/user');
|
||||
var EmailUnsubscription = require('../models/emailUnsubscription');
|
||||
var User = require('../models/user').model;
|
||||
var EmailUnsubscription = require('../models/emailUnsubscription').model;
|
||||
var utils = require('../utils');
|
||||
var i18n = require('../../../common').i18n;
|
||||
|
||||
var api = module.exports = {};
|
||||
|
||||
api.unsubscribe = function(req, res, next){
|
||||
if(!req.query.code) return next(new Error('Missing unsubscription code.'));
|
||||
if(!req.query.code) return res.json(500, {err: 'Missing unsubscription code.'});
|
||||
|
||||
var data = JSON.parse(utils.decrypt(req.query.code));
|
||||
|
||||
if(data._id){
|
||||
User.update({_id: data._id}, {
|
||||
$set: {}
|
||||
$set: {'preferences.emailNotifications.unsubscribeFromAll': true}
|
||||
}, {multi: false}, function(err, nAffected){
|
||||
if(err) return next(err);
|
||||
if(nAffected !== 1) return next(new Error('User not found'));
|
||||
if(nAffected !== 1) return res.json(404, {err: 'User not found'});
|
||||
|
||||
res.send('Unsubscribed!');
|
||||
res.send('<h1>' + i18n.t('unsubscribedSuccessfully', null, req.language) + '</h1>' + i18n.t('unsubscribedTextUsers', null, req.language));
|
||||
});
|
||||
}else{
|
||||
EmailUnsubscription.findOne({email: data.email}, function(err, res){
|
||||
EmailUnsubscription.findOne({email: data.email}, function(err, doc){
|
||||
if(err) return next(err);
|
||||
if(res) return next(new Error('Email address already unsubscribed'));
|
||||
var okRes = '<h1>' + i18n.t('unsubscribedSuccessfully', null, req.language) + '</h1>' + i18n.t('unsubscribedTextOthers', null, req.language);
|
||||
|
||||
if(doc) return res.send(okRes);
|
||||
|
||||
EmailUnsubscription.create({email: data.email}, function(err, res){
|
||||
EmailUnsubscription.create({email: data.email}, function(err, doc){
|
||||
if(err) return next(err);
|
||||
|
||||
res.send('Unsubscribed!');
|
||||
res.send(okRes);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue