72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
/**
|
|
* Run
|
|
*
|
|
* @module :: Model
|
|
* @description :: A short summary of how this model works and what it represents.
|
|
* @docs :: http://sailsjs.org/#!documentation/models
|
|
*/
|
|
var nodemailer = require('nodemailer');
|
|
|
|
module.exports = {
|
|
|
|
attributes: {
|
|
name: {
|
|
type: 'string',
|
|
required: true
|
|
},
|
|
creatorName: {
|
|
type: 'string',
|
|
required: true
|
|
},
|
|
creatorEmail: {
|
|
type: 'email',
|
|
required: true
|
|
},
|
|
invitees: {
|
|
type: 'array'
|
|
},
|
|
menuUrl: {
|
|
type: 'url'
|
|
},
|
|
restaurant: 'string'
|
|
},
|
|
|
|
afterCreate: function(values, next) {
|
|
var transport = nodemailer.createTransport('SMTP', {
|
|
service: "Gmail",
|
|
auth: {
|
|
user: "ben.ramey@gmail.com",
|
|
pass: "Mila(18)?"
|
|
}
|
|
});
|
|
|
|
var options = {
|
|
from: values.creatorName + " <" + values.creatorEmail + ">",
|
|
subject: "You've been invited to a lunch run!",
|
|
text: "You've been invited to " + values.creatorName + "'s lunch run: '"
|
|
+ values.name + "'! \n\n Put in your order here:\nhttp://www.lunchrun.me/#/run/"
|
|
+ values.id + "/order/"
|
|
};
|
|
|
|
for (var idx in values.invitees) {
|
|
var invitee = values.invitees[idx];
|
|
var specificOptions = options;
|
|
specificOptions.to = invitee.name + " <" + invitee.email + ">";
|
|
specificOptions.text += invitee.name;
|
|
|
|
console.log(specificOptions);
|
|
transport.sendMail(specificOptions, function(err, response) {
|
|
if (err) {
|
|
console.log(err);
|
|
} else {
|
|
console.log("message sent from: " + values.creatorEmail);
|
|
}
|
|
});
|
|
}
|
|
|
|
transport.close();
|
|
|
|
next();
|
|
},
|
|
};
|