got email pug templates to work

This commit is contained in:
David Baldwynn 2017-10-27 19:29:19 -07:00
parent b0f03d1f0a
commit 4f7d646edd
11 changed files with 103 additions and 222 deletions

View file

@ -9,16 +9,10 @@ var errorHandler = require('../errors.server.controller'),
config = require('../../../config/config'),
User = mongoose.model('User'),
tokgen = require('../../libs/tokenGenerator'),
fs = require('fs');
require.extensions['.html'] = function (module, filename) {
module.exports = fs.readFileSync(filename, 'utf8');
};
var welcomeEmail = require("../../views/welcome.email.view.html");
var verificationEmail = require("../../views/verification.email.view.html");
fs = require('fs'),
i18n = require('i18n'),
async = require('async'),
pug = require('pug');
var nev = require('email-verification')(mongoose);
@ -26,6 +20,15 @@ var nev = require('email-verification')(mongoose);
var config_nev = function () {
nev.configure({
verifyMailOptions: {
from: config.mailer.from
},
confirmMailOptions: {
from: config.mailer.from
},
persistentUserModel: User,
tempUserCollection: config.tempUserCollection,
emailAndUsernameUnique: true,
@ -33,19 +36,7 @@ var config_nev = function () {
verificationURL: config.baseUrl+'/#!/verify/${URL}',
transportOptions: config.mailer.options,
verifyMailOptions: {
from: config.mailer.from,
subject: '✔ Activate your new TellForm account!',
html: verificationEmail,
text: 'Please verify your account by clicking the following link, or by copying and pasting it into your browser: ${URL}'
},
confirmMailOptions: {
from: config.mailer.from,
subject: '✔ Welcome to {{app.title}}!',
html: welcomeEmail,
text: 'Your account has been successfully verified.'
},
verifySendMailCallback: function(err, info) {
if (err) {
throw err;
@ -63,13 +54,22 @@ var config_nev = function () {
throw err;
}
});
};
config_nev();
exports.validateVerificationToken = function(req, res){
nev.confirmTempUser(req.params.token, function(err, user) {
const fn = pug.compileFile(__dirname + "/../../views/welcome.email.view.pug");
var renderedHtml = fn(res.locals);
var emailTemplate = {
subject: i18n.__('WELCOME_EMAIL_SUBJECT', config.app.title),
html: renderedHtml,
text: i18n.__('WELCOME_EMAIL_TEXT')
};
nev.confirmTempUser(req.params.token, emailTemplate, function(err, user) {
if(err) {
return res.status(500).send( {message: err } );
} else if (user){
@ -83,7 +83,16 @@ exports.validateVerificationToken = function(req, res){
};
exports.resendVerificationEmail = function(req, res, next){
nev.resendVerificationEmail(req.body.email, function(err, userFound) {
const fn = pug.compileFile(__dirname + "/../../views/verification.email.view.pug");
var renderedHtml = fn(res.locals);
var emailTemplate = {
subject: i18n.__('VERIFICATION_EMAIL_SUBJECT'),
html: renderedHtml,
text: i18n.__('VERIFICATION_EMAIL_TEXT')
};
nev.resendVerificationEmail(req.body.email, emailTemplate, function(err, userFound) {
if(err) {
return res.status(500).send( {message: errorHandler.getErrorMessage(err) } );
}
@ -112,6 +121,7 @@ exports.signup = function(req, res) {
// Then save the temporary user
nev.createTempUser(user, function (err, existingPersistentUser, newTempUser) {
if (err) {
console.log(err);
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
@ -120,10 +130,18 @@ exports.signup = function(req, res) {
// new user created
if (newTempUser) {
var URL = newTempUser[nev.options.URLFieldName];
nev.sendVerificationEmail(user.email, URL, function (sendEmailErr, info) {
if (sendEmailErr) {
const fn = pug.compileFile(__dirname + "/../../views/verification.email.view.pug");
var renderedHtml = fn(res.locals);
var URL = newTempUser[nev.options.URLFieldName];
var emailTemplate = {
subject: i18n.__('VERIFICATION_EMAIL_SUBJECT'),
html: renderedHtml,
text: i18n.__('VERIFICATION_EMAIL_TEXT')
};
nev.sendVerificationEmail(user.email, URL, emailTemplate, function (sendEmailErr, info) {
if (sendEmailErr) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
@ -131,7 +149,7 @@ exports.signup = function(req, res) {
return res.status(200).send('An email has been sent to you. Please check it to verify your account.');
});
} else {
return res.status(400).send({message: 'Error: User already exists!'});
return res.status(400).send({message: 'User with username/email already exists!'});
}
});
};

View file

@ -48,7 +48,7 @@ var validateLocalStrategyPassword = function(password) {
* A Validation function for username
*/
var validateUsername = function(username) {
return (username.match(/^[a-zA-Z0-9]+$/) !== null);
return (username.match(/^[a-zA-Z0-9.-_]+$/) !== null);
};
@ -70,22 +70,15 @@ var UserSchema = new Schema({
type: String,
trim: true,
unique: 'Account already exists with this email',
required: 'Please enter your email',
validate: {
validator: validateLocalStrategyProperty,
message: 'Please fill in your email'
},
match: [/.+\@.+\..+/, 'Please fill a valid email address']
match: [/.+\@.+\..+/, 'Please fill a valid email address'],
required: [true, 'Email is required']
},
username: {
type: String,
unique: true,
required: true,
lowercase: true,
validate: {
validator: validateUsername,
message: 'Please use a valid username'
}
match: [/^[a-zA-Z0-9\.\-\_]+$/, 'Username can only contain alphanumeric characters and \'_\', \'-\' and \'.\''],
required: [true, 'Username is required']
},
passwordHash: {
type: String,
@ -96,7 +89,6 @@ var UserSchema = new Schema({
},
provider: {
type: String,
required: 'Provider is required',
default: 'local'
},
providerData: {},
@ -112,7 +104,6 @@ var UserSchema = new Schema({
type: String,
enum: ['en', 'fr', 'es', 'it', 'de'],
default: 'en',
required: 'User must have a language'
},
lastModified: {
type: Date

View file

@ -5,4 +5,8 @@ block content
div.row.valign
h3.col-md-12.text-center=__('500_HEADER')
div.col-md-4.col-md-offset-4
div.col-md-12.text-center(style="padding-bottom: 50px;")=__('500_BODY')
if process.env.NODE_ENV == 'development'
div.col-md-12.text-center(style="padding-bottom: 50px;")
| #{error}
else
div.col-md-12.text-center(style="padding-bottom: 50px;")=__('500_BODY')

View file

@ -5,42 +5,45 @@ block content
script(src='/static/lib/file-saver.js/FileSaver.js', type='text/javascript')
//Embedding The User Object
script(type='text/javascript') var user = null;
//Embedding The User Object
script(type='text/javascript').
var user = null;
//Embedding The signupDisabled Boolean
script(type='text/javascript').
var signupDisabled = !{signupDisabled};
var socketPort = false;
var socketUrl = false;
var subdomainsDisabled = !{subdomainsDisabled};
//Embedding The signupDisabled Boolean
script(type='text/javascript').
var signupDisabled = !{signupDisabled};
var socketPort = false;
var socketUrl = false;
var subdomainsDisabled = !{subdomainsDisabled};
//Embedding socketPort
if socketPort
script(type='text/javascript').
socketPort = !{socketPort}
//Embedding socketPort
if socketPort
script(type='text/javascript').
socketPort = !{socketPort}
//Embedding socketUrl
if socketUrl
script(type='text/javascript').
socketUrl = !{socketUrl}
//Embedding socketUrl
if socketUrl
script(type='text/javascript').
socketUrl = !{socketUrl}
//Socket.io Client Dependency
script(src='https://cdn.socket.io/socket.io-1.4.5.js')
//Socket.io Client Dependency
script(src='https://cdn.socket.io/socket.io-1.4.5.js')
//Bower JS dependencies
each bowerJSFile in bowerJSFiles
script(type='text/javascript', src=bowerJSFile)
// end Bower JS dependencies
//Bower JS dependencies
each bowerJSFile in bowerJSFiles
script(type='text/javascript', src=bowerJSFile)
// end Bower JS dependencies
script(type='text/javascript', src='https://cdnjs.cloudflare.com/ajax/libs/angular-strap/2.3.8/angular-strap.min.js')
script(type='text/javascript', src='https://cdnjs.cloudflare.com/ajax/libs/angular-strap/2.3.8/angular-strap.min.js')
//Application JavaScript Files
each jsFile in jsFiles
script(type='text/javascript', src=jsFile)
// end Application Javascript dependencies
//Application JavaScript Files
each jsFile in jsFiles
script(type='text/javascript', src=jsFile)
// end Application Javascript dependencies
if process.env.NODE_ENV === 'development'
script(type='text/javascript', src='http://#{request.hostname}:35729/livereload.js')
script(src='https://cdn.ravenjs.com/2.3.0/angular/raven.min.js')
script Raven.config('https://825fefd6b4ed4a4da199c1b832ca845c@sentry.tellform.com/2').install();
if process.env.NODE_ENV === 'development'
script(type='text/javascript', src='http://#{request.hostname}:35729/livereload.js')
script(src='https://cdn.ravenjs.com/2.3.0/angular/raven.min.js')
script Raven.config('https://825fefd6b4ed4a4da199c1b832ca845c@sentry.tellform.com/2').install();

View file

@ -1,65 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<head>
@import url(//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&subset=latin,latin-ext);
<style>
a {
color: #007ee6;
text-decoration: none;
}
</style>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
</head>
<body style="padding: 0; width: 100% !important; -webkit-text-size-adjust: 100%; margin: 0; -ms-text-size-adjust: 100%;" marginheight="0" marginwidth="0">
<center>
<table cellpadding="8" cellspacing="0" style="*width: 540px; padding: 0; width: 100% !important; background: #ffffff; margin: 0; background-color: #ffffff;" border="0">
<tr>
<td valign="top">
<table cellpadding="0" cellspacing="0" style="border-radius: 6px; -webkit-border-radius: 6px; border: 1px #c0c0c0 solid; -moz-border-radius: 6px;" border="0" align="center">
<tr>
<td colspan="3" height="6"></td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" style="line-height: 25px;" border="0" align="center">
<tr>
<td colspan="3" height="30"></td>
</tr>
<tr>
<td width="36"></td>
<td width="454" align="left" style="color: #444444; border-collapse: collapse; font-size: 11pt; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; max-width: 454px;" valign="top">
<p>Hello there!</p>
<p>Welcome to TellForm! Here is a special link to activate your new account:</p>
<p><a href="https://${URL}">Activate my account</a></p>
<p>Thanks so much for using our services! If you have any questions, or suggestions, please feel free to email us here at&nbsp;<a href="mailto:team@tellform.com">team@tellform.com</a>.</p>
<p> - The TellForm team</p>
</td>
<td width="36"></td>
</tr>
<tr>
<td colspan="3" height="36"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" align="center" border="0">
<tr>
<td height="10"></td>
</tr>
<tr>
<td style="padding: 0; border-collapse: collapse;">
<table cellpadding="0" cellspacing="0" align="center" border="0">
<tr style="color: #c0c0c0; font-size: 11px; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; -webkit-text-size-adjust: none;">
<td width="400" align="left"></td>
<td width="128" align="right">© TellForm 2017</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</head>

View file

@ -1,8 +1,6 @@
doctype html
html
head
style.
@import url(//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&subset=latin,latin-ext);
a {
color: #007ee6;
text-decoration: none;
@ -26,11 +24,11 @@ html
td(colspan='3', height='30')
tr
td(width='36')
td(width='454', align='left', style='color: #444444; border-collapse: collapse; font-size: 11pt; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; max-width: 454px', valign='top')
td(width='454', align='left', style="color: #444444; border-collapse: collapse; font-size: 11pt; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; max-width: 454px", valign='top')
p=__('EMAIL_GREETING')
p=__('VERIFICATION_EMAIL_PARAGRAPH_1')
p
a(href='https://${URL}')=('VERIFICATION_EMAIL_LINK_TEXT')
a(href='https://${URL}')=__('VERIFICATION_EMAIL_LINK_TEXT')
p=__('VERIFICATION_EMAIL_PARAGRAPH_2')
a(href='mailto:team@tellform.com')
| team@tellform.com
@ -46,6 +44,6 @@ html
td(style='padding: 0; border-collapse: collapse')
table(cellpadding='0', cellspacing='0', align='center', border='0')
tbody
tr(style='color: #c0c0c0; font-size: 11px; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; -webkit-text-size-adjust: none')
tr(style="color: #c0c0c0; font-size: 11px; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; -webkit-text-size-adjust: none")
td(width='400', align='left')
td(width='128', align='right') © TellForm 2017

View file

@ -1,64 +0,0 @@
<!DOCTYPE html>
<html>
<head>@import url(//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&subset=latin,latin-ext);
<style>
a {
color: #007ee6;
text-decoration: none;
}
</style>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body style="padding: 0; width: 100% !important; -webkit-text-size-adjust: 100%; margin: 0; -ms-text-size-adjust: 100%;" marginheight="0" marginwidth="0">
<center>
<table cellpadding="8" cellspacing="0" style="*width: 540px; padding: 0; width: 100% !important; background: #ffffff; margin: 0; background-color: #ffffff;" border="0">
<tr>
<td valign="top">
<table cellpadding="0" cellspacing="0" style="border-radius: 6px; -webkit-border-radius: 6px; border: 1px #c0c0c0 solid; -moz-border-radius: 6px;" border="0" align="center">
<tr>
<td colspan="3" height="6"></td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" style="line-height: 25px;" border="0" align="center">
<tr>
<td colspan="3" height="30"></td>
</tr>
<tr>
<td width="36"></td>
<td width="454" align="left" style="color: #444444; border-collapse: collapse; font-size: 11pt; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; max-width: 454px;" valign="top">
<p>Hello there!</p>
<p>We would like to welcome you as our newest member!</p>
<p>Thanks so much for using TellForm! If you have any questions, or suggestions, please feel free to email us here at&nbsp;<a href="mailto:team@tellform.com">team@tellform.com</a>.</p>
<p> - The TellForm team</p>
</td>
<td width="36"></td>
</tr>
<tr>
<td colspan="3" height="36"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" align="center" border="0">
<tr>
<td height="10"></td>
</tr>
<tr>
<td style="padding: 0; border-collapse: collapse;">
<table cellpadding="0" cellspacing="0" align="center" border="0">
<tr style="color: #c0c0c0; font-size: 11px; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; -webkit-text-size-adjust: none;">
<td width="400" align="left"></td>
<td width="128" align="right">© TellForm 2017</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>

View file

@ -1,8 +1,6 @@
doctype html
html
head
style.
@import url(//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&subset=latin,latin-ext);
a {
color: #007ee6;
text-decoration: none;
@ -27,7 +25,7 @@ html
td(colspan='3', height='30')
tr
td(width='36')
td(width='454', align='left', style='color: #444444; border-collapse: collapse; font-size: 11pt; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; max-width: 454px', valign='top')
td(width='454', align='left', style="color: #444444; border-collapse: collapse; font-size: 11pt; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; max-width: 454px", valign='top')
p=__('EMAIL_GREETING')
p=__('WELCOME_EMAIL_PARAGRAPH_1')
p=__('WELCOME_EMAIL_PARAGRAPH_2')
@ -45,6 +43,6 @@ html
td(style='padding: 0; border-collapse: collapse')
table(cellpadding='0', cellspacing='0', align='center', border='0')
tbody
tr(style='color: #c0c0c0; font-size: 11px; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; -webkit-text-size-adjust: none')
tr(style="color: #c0c0c0; font-size: 11px; font-family: 'Open Sans', 'Lucida Grande', 'Segoe UI', Arial, Verdana, 'Lucida Sans Unicode', Tahoma, 'Sans Serif'; -webkit-text-size-adjust: none")
td(width='400', align='left')
td(width='128', align='right') © TellForm 2017

View file

@ -162,8 +162,6 @@ module.exports = function(db) {
app.use(function(req, res, next) {
// express helper for natively supported engines
res.locals.__ = res.__ = function() {
console.log('\n\n\n\n\n\nres.locals.__');
console.log(arguments);
return i18n.__.apply(req, arguments);
};

View file

@ -7,7 +7,11 @@
"VERIFICATION_EMAIL_PARAGRAPH_1": "Welcome to TellForm! Here is a special link to activate your new account:",
"VERIFICATION_EMAIL_LINK_TEXT": "Activate my account",
"VERIFICATION_EMAIL_PARAGRAPH_2": "Thanks so much for using our services! If you have any questions, or suggestions, please feel free to email us here at",
"VERIFICATION_EMAIL_SUBJECT": "Activate your new TellForm account!",
"VERIFICATION_EMAIL_TEXT": "Please verify your account by clicking the following link, or by copying and pasting it into your browser: ${URL}",
"EMAIL_SIGNATURE": "- The TellForm team",
"WELCOME_EMAIL_PARAGRAPH_1": "We would like to welcome you as our newest member!",
"WELCOME_EMAIL_PARAGRAPH_2": "We hope you enjoy using TellForm! If you have any trouble please feel free to email us here at"
"WELCOME_EMAIL_PARAGRAPH_2": "We hope you enjoy using TellForm! If you have any trouble please feel free to email us here at",
"WELCOME_EMAIL_SUBJECT": "Welcome to %s!",
"WELCOME_EMAIL_TEXT": "Your account has been successfully verified."
}

View file

@ -37,7 +37,7 @@
"cookie-parser": "~1.4.0",
"deep-diff": "^0.3.4",
"dotenv": "^2.0.0",
"email-verification": "~0.4.1",
"email-verification": "github:tellform/node-email-verification",
"express": "~4.13.3",
"express-session": "~1.12.1",
"glob": "^7.0.3",
@ -52,10 +52,6 @@
"grunt-ng-annotate": "~1.0.1",
"helmet": "3.5.0",
"i18n": "^0.8.3",
"i18n-node": "^2.1.5",
"i18n-x": "^0.1.5",
"i18next": "^10.0.3",
"i18next-express-middleware": "^1.0.7",
"jit-grunt": "^0.9.1",
"lodash": "^4.17.4",
"main-bower-files": "~2.9.0",