diff --git a/app/models/user.server.model.js b/app/models/user.server.model.js index b2da78df..f73b27c5 100755 --- a/app/models/user.server.model.js +++ b/app/models/user.server.model.js @@ -133,6 +133,28 @@ UserSchema.plugin(mUtilities.timestamp, { }); +UserSchema.pre('find', 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" ', // 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); + }); + } +}); + UserSchema.pre('save', function (next) { //Change username if it is still the user's email diff --git a/config/express.js b/config/express.js index ecebbb93..ed4d5299 100755 --- a/config/express.js +++ b/config/express.js @@ -72,6 +72,7 @@ module.exports = function(db) { var subdomains = req.subdomains; var host = req.hostname; + if(subdomains.slice(0, 4).join('.')+'' === '1.0.0.127'){ subdomains = subdomains.slice(4); }