mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 18:11:40 -05:00
added generateEmailHash helper method
This commit is contained in:
parent
6a4e32be05
commit
fa1f8db277
3 changed files with 20 additions and 12 deletions
|
@ -20,14 +20,4 @@ sendEmail = function(to, subject, text, html){
|
|||
text: text,
|
||||
html: html
|
||||
});
|
||||
};
|
||||
|
||||
Meteor.methods({
|
||||
sendNotificationEmail: function(to, notificationId){
|
||||
// Note: we query the DB instead of simply passing arguments from the client
|
||||
// to make sure our email method cannot be used for spam
|
||||
var notification = Notifications.findOne(notificationId);
|
||||
var n = getNotification(notification.event, notification.properties);
|
||||
sendEmail(to, n.subject, n.text, n.html);
|
||||
}
|
||||
})
|
||||
};
|
|
@ -15,12 +15,26 @@ createNotification = function(event, properties, userToNotify, userDoingAction){
|
|||
var newNotificationId=Notifications.insert(notification);
|
||||
|
||||
if(userToNotify.profile && userToNotify.profile.notificationsFrequency === 1){
|
||||
Meteor.call('sendNotificationEmail', getEmail(userToNotify), newNotificationId);
|
||||
Meteor.call('sendNotificationEmail', userToNotify, newNotificationId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
getUnsubscribeLink = function(user){
|
||||
return Meteor.absoluteUrl()+'unsubscribe/'+user.email_hash;
|
||||
};
|
||||
|
||||
Meteor.methods({
|
||||
sendNotificationEmail: function(userToNotify, notificationId){
|
||||
// Note: we query the DB instead of simply passing arguments from the client
|
||||
// to make sure our email method cannot be used for spam
|
||||
var notification = Notifications.findOne(notificationId);
|
||||
var n = getNotification(notification.event, notification.properties);
|
||||
var to = getEmail(userToNotify);
|
||||
var text = n.text + '\n\n Unsubscribe from all notifications: '+getUnsubscribeLink(userToNotify);
|
||||
var html = n.html + '<br/><br/><a href="'+getUnsubscribeLink(userToNotify)+'">Unsubscribe from all notifications</a>';
|
||||
sendEmail(to, n.subject, text, html);
|
||||
},
|
||||
unsubscribeUser : function(hash){
|
||||
// TO-DO: currently, if you have somebody's email you can unsubscribe them
|
||||
// A site-specific salt should be added to the hashing method to prevent this
|
||||
|
|
|
@ -48,6 +48,10 @@ Meteor.methods({
|
|||
var ageInHours = (new Date().getTime() - object.submitted) / (60 * 60 * 1000);
|
||||
var newScore = baseScore / Math.pow(ageInHours + 2, 1.3);
|
||||
return Math.abs(object.score - newScore);
|
||||
},
|
||||
generateEmailHash: function(){
|
||||
var email_hash = CryptoJS.MD5(getEmail(Meteor.user()).trim().toLowerCase()).toString();
|
||||
Meteor.users.update(Meteor.userId(), {$set : {email_hash : email_hash}});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue