added username reminder message for older users

This commit is contained in:
David Baldwynn 2016-07-04 17:24:27 -07:00
parent 17530c1cfb
commit 2b3f314db8

View file

@ -9,7 +9,13 @@ var mongoose = require('mongoose'),
config = require('../../config/config'),
fs = require('fs-extra'),
mUtilities = require('mongoose-utilities'),
path = require('path');
path = require('path'),
querystring = require('querystring'),
config = require('../../config/config'),
nodemailer = require('nodemailer');
var smtpTransport = nodemailer.createTransport(config.mailer.options);
/**
* A Validation function for local strategy properties
@ -126,8 +132,29 @@ UserSchema.plugin(mUtilities.timestamp, {
useVirtual: false
});
//Create folder for user's pdfs
UserSchema.pre('save', function (next) {
//Change username if it is still the user's email
if(this.username === this.email){
var emailUsername = this.email.split('@')[0];
this.username = querystring.stringify({ query: emailUsername });
var mailOptions = {
from: '"TellForm Support" <noreply@tellform.com>', // sender address
to: this.email, // list of receivers
subject: 'Your TellForm Username has Changed', // Subject line
text: 'Due to upgrades, your TellForm username has change from ' + this.email + ' to ' + this.username + '. Please use your new username to login.\n Using your old username will not work.\n We apologize for the inconvenience,\n - the TellForm team', // plaintext body
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.error(error);
}
console.log('Username change message sent: ' + info.response);
});
}
//Create folder for user's pdfs
if(process.env.NODE_ENV === 'local-development'){
var newDestination = path.join(config.pdfUploadPath, this.username.replace(/ /g,'')),
stat = null;