add ability to unsubscribe from a single event using a dedicated link

This commit is contained in:
Matteo Pagliazzi
2015-02-23 21:25:01 +01:00
parent b010a53bed
commit 4151b0733f
3 changed files with 23 additions and 2 deletions

View File

@@ -99,6 +99,7 @@
"remindersToLogin": "Reminders to check in to HabitRPG", "remindersToLogin": "Reminders to check in to HabitRPG",
"unsubscribeAllEmails": "Check to Unsubscribe from Emails", "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.", "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.",
"subscriptionRateText": "Recurring $<%= price %> every <%= months %> months", "subscriptionRateText": "Recurring $<%= price %> every <%= months %> months",
"benefits": "Benefits", "benefits": "Benefits",
"coupon": "Coupon", "coupon": "Coupon",

View File

@@ -15,6 +15,27 @@ habitrpg.controller('SettingsCtrl',
// }); // });
// } // }
// A simple object to map the key stored in the db (user.preferences.emailNotification[key])
// to its string but ONLY when the preferences' key and the string key don't match
var mapPrefToEmailString = {
'importantAnnouncements': 'inactivityEmails'
};
// If ?unsubFrom param is passed with valid email type,
// automatically unsubscribe users from that email and
// show an alert
$timeout(function(){
var unsubFrom = $location.search().unsubFrom;
if(unsubFrom){
var emailPrefKey = 'preferences.emailNotifications.' + qs.unsubFrom;
var emailTypeString = env.t(mapPrefToEmailString[qs.unsubFrom] || qs.unsubFrom);
User.set({emailPrefKey: false});
User.user.preferences.emailNotifications[qs.unsubFrom] = false;
Notification.text(env.t('correctlyUnsubscribedEmailType', {emailType: emailTypeString}));
$location.search({});
}
}, 500);
$scope.hideHeader = function(){ $scope.hideHeader = function(){
User.set({"preferences.hideHeader":!User.user.preferences.hideHeader}) User.set({"preferences.hideHeader":!User.user.preferences.hideHeader})
if (User.user.preferences.hideHeader && User.user.preferences.stickyHeader){ if (User.user.preferences.hideHeader && User.user.preferences.stickyHeader){

View File

@@ -56,8 +56,7 @@ module.exports.getUserInfo = getUserInfo;
module.exports.txnEmail = function(mailingInfoArray, emailType, variables){ module.exports.txnEmail = function(mailingInfoArray, emailType, variables){
var mailingInfoArray = Array.isArray(mailingInfoArray) ? mailingInfoArray : [mailingInfoArray]; var mailingInfoArray = Array.isArray(mailingInfoArray) ? mailingInfoArray : [mailingInfoArray];
var variables = [ var variables = [
{name: 'BASE_URL', content: baseUrl}, {name: 'BASE_URL', content: baseUrl}
{name: 'EMAIL_SETTINGS_URL', content: baseUrl + '/#/options/settings/notifications'}
].concat(variables || []); ].concat(variables || []);
// It's important to pass at least a user with its `preferences` as we need to check if he unsubscribed // It's important to pass at least a user with its `preferences` as we need to check if he unsubscribed