-
Notifications
You must be signed in to change notification settings - Fork 1
/
mailHandler.js
100 lines (79 loc) · 3.47 KB
/
mailHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
if (Meteor.isServer) {
Meteor.startup(function () {
//todo promote in a configuration file
process.env.MAIL_URL = 'smtp://postmaster%40scrummaster.com:[email protected]:587';
});
}
if (Meteor.isClient) {
Template.team.events({
'click .sendMail' : function () {
var msg = " invites you to join ScrumMaster!!! \n Click the link below: \n";
var mailTo = $('#invitationMail').val();
var current_team = Session.get('currentTeam');
var current_product = Session.get('currentProduct');
var role = $('#invitationRole').val();
console.log("@@@ current team: "+current_team );
console.log("@@@ current product: "+current_product );
Meteor.call('sendInvitation', mailTo, msg, role, current_team, current_product, function (error, result) {
if (error) {
//notify that there's a problem
$.pnotify({
title: 'Error!',
text: '\nProblem while sending invitation to '+ mailTo +'\n'+((error.message) ? error.message : ''),
type: 'error',
hide: false
});
}
else {
//notify that the invitation has been sent
$.pnotify({
title: 'Success!',
text: '\nInvitation to '+ mailTo +' has been sent!',
type: 'success',
hide: false
});
}
}); //notify that the invitation has been sent
//todo send a notification
$('#invitationMail').val("");
//prevent reload
return false;
}
});
}
var sendInvitation = function ( mailFrom, mailTo, msg, role, current_team, current_product) {
// generazione token
var result = {};
var stampedToken = Accounts._generateStampedLoginToken();
result.token = stampedToken.token;
console.log("mailFrom: "+mailFrom);
console.log("mailTo: "+mailTo);
console.log("msg: "+msg);
console.log("current_team: "+current_team);
console.log("current_product: "+current_product);
// salvo in InvitationToken il token appen creato
var timestamp = new Date();
InvitationToken.insert({token: result.token, product: current_product, team: current_team, date: timestamp});
var link = Meteor.absoluteUrl() + current_product + "/joinTeam/" + current_team + "?" + "param="+role+ "&tk="+ result.token;
var current_user = Meteor.users.findOne( Meteor.userId() );
console.dir("Current user: " + JSON.stringify(current_user));
Email.send({
from: mailFrom,
to: mailTo,
replyTo: mailFrom || undefined,
subject: "ScrumMaster Join Request",
text: "Hello "+mailTo+",\n\n"+
current_user.profile.given_name + msg +
link + "\n\n"+
"ScrumMaster Team.\n"+
Meteor.absoluteUrl()+"\n"
});
}
Meteor.methods({
'sendInvitation': function (mailTo, msg, role, current_team, current_product) {
if (Meteor.isServer)
// al posto di "[email protected]", si potrebbe pensare di prendere la mail dell'utente loggato
// Meteor.users.findOne(Meteor.userId).profile.email
sendInvitation("[email protected]", mailTo, msg, role, current_team, current_product);
}
});