klark-js-plugins
Advanced tools
Comparing version 1.0.24 to 1.0.25
{ | ||
"name": "klark-js-plugins", | ||
"version": "1.0.24", | ||
"version": "1.0.25", | ||
"description": "Plugin modules for KlarkJS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,3 +18,3 @@ 'use strict'; | ||
if (!this.isModified(passField) && !this.isNew) { | ||
if (!this.isModified(passField) && !this.isNew || !user[passField]) { | ||
return next(); | ||
@@ -28,3 +28,3 @@ } | ||
return q.promisify(function(cb) { | ||
return $bcrypt.hash(user.password, salt, cb); | ||
return $bcrypt.hash(user[passField], salt, cb); | ||
}); | ||
@@ -60,2 +60,2 @@ }) | ||
}); | ||
}); |
'use strict'; | ||
KlarkModule(module, 'krkModelsUser', function( | ||
KlarkModule(module, 'krkModelsUserExtension', function( | ||
_, | ||
@@ -11,32 +11,89 @@ q, | ||
krkMiddlewarePermissionsRoles, | ||
krkDbMongoosePluginsPassword | ||
krkDbMongoosePluginsPassword, | ||
krkNotificationsEmail | ||
) { | ||
// seconds, after signup of the account, how long will the user remain until it will be validated | ||
var USER_ACCOUNT_VALIDATION_PERIOD = 1 * 24 * 60 * 60 * 1000; | ||
krkDbMongooseConnector.decorateMongoosePromises(); | ||
var schema = new $mongoose.Schema({ | ||
name: {type: String, maxlength: [64], unique: true, required: true}, | ||
email: {type: $mongoose.SchemaTypes.Email, unique: true, required: true}, | ||
password: {type: String, required: true}, | ||
phone: {type: String, maxlength: [32]}, | ||
lastLogin: {type: Date, required: true, default: Date.now}, | ||
validationExpiresAt: { type: Date, default: Date.now, expires: USER_ACCOUNT_VALIDATION_PERIOD }, | ||
validationToken: {type: String, maxlength: [64]}, | ||
totalLogins: {type: Number, required: true, min: 0, default: 0}, | ||
role: {type: String, enum: krkMiddlewarePermissionsRoles, required: true}, | ||
validatedByAdmin: {type: Boolean, required: true}, | ||
preferences: {type: $mongoose.Schema.Types.Mixed} | ||
}); | ||
const defaultOpts = { | ||
validatedByAdmin: true, | ||
userAccountValidationPeriod: 1 * 24 * 60 * 60 * 1000, | ||
supportedLanguages: ['en'], | ||
onSchemaOptions: _.identity, | ||
onSchemaMethods: _.identity | ||
}; | ||
schema.plugin(krkDbMongoosePluginsPassword, { passwordField: 'password' }); | ||
schema.plugin($mongooseCreatedmodified.createdModifiedPlugin); | ||
schema.methods.getSafely = getSafely; | ||
schema.methods.updateLoginInfo = updateLoginInfo; | ||
schema.statics.verifyAccount = verifyAccount; | ||
schema.statics.invalidateAccount = invalidateAccount; | ||
schema.statics.validateByAdmin = validateByAdmin; | ||
return { | ||
createSchema: createSchema | ||
}; | ||
return $mongoose.model('User', schema); | ||
function createSchema(opts) { | ||
var options = _.defaults(opts, defaultOpts); | ||
var schemaOpts = { | ||
email: {type: $mongoose.SchemaTypes.Email, unique: true, required: true}, | ||
password: {type: String}, | ||
lastLogin: {type: Date, default: Date.now}, | ||
validationExpiresAt: { type: Date, expires: options.userAccountValidationPeriod }, | ||
validationToken: {type: String, maxlength: [64]}, | ||
totalLogins: {type: Number, min: 0, default: 0}, | ||
role: {type: String, enum: krkMiddlewarePermissionsRoles, required: true}, | ||
lang: {type: String, enum: options.supportedLanguages, default: options.supportedLanguages[0]}, | ||
}; | ||
if (options.validatedByAdmin) { | ||
schemaOpts.validatedByAdmin = {type: Boolean, required: true}; | ||
} | ||
schemaOpts = options.onSchemaOptions(schemaOpts); | ||
var schema = new $mongoose.Schema(schemaOpts); | ||
schema.plugin(krkDbMongoosePluginsPassword, { passwordField: 'password' }); | ||
schema.plugin($mongooseCreatedmodified.createdModifiedPlugin); | ||
schema.methods.getSafely = getSafely; | ||
schema.methods.updateLoginInfo = updateLoginInfo; | ||
schema.methods.sendVerificationEmail = sendVerificationEmail; | ||
schema.methods.sendResetPasswordEmail = sendResetPasswordEmail; | ||
schema.statics.verifyAccount = verifyAccount; | ||
schema.statics.invalidateAccount = invalidateAccount; | ||
if (options.validatedByAdmin) { | ||
schema.statics.validateByAdmin = validateByAdmin; | ||
} | ||
schema = options.onSchemaMethods(schema); | ||
return $mongoose.model('User', schema); | ||
} | ||
// seconds, after signup of the account, how long will the user remain until it will be validated | ||
// var USER_ACCOUNT_VALIDATION_PERIOD = 1 * 24 * 60 * 60 * 1000; | ||
// krkDbMongooseConnector.decorateMongoosePromises(); | ||
// var schema = new $mongoose.Schema({ | ||
// name: {type: String, maxlength: [64], unique: true, required: true}, | ||
// email: {type: $mongoose.SchemaTypes.Email, unique: true, required: true}, | ||
// password: {type: String, required: true}, | ||
// phone: {type: String, maxlength: [32]}, | ||
// lastLogin: {type: Date, required: true, default: Date.now}, | ||
// validationExpiresAt: { type: Date, default: Date.now, expires: USER_ACCOUNT_VALIDATION_PERIOD }, | ||
// validationToken: {type: String, maxlength: [64]}, | ||
// totalLogins: {type: Number, required: true, min: 0, default: 0}, | ||
// role: {type: String, enum: krkMiddlewarePermissionsRoles, required: true}, | ||
// validatedByAdmin: {type: Boolean, required: true}, | ||
// preferences: {type: $mongoose.Schema.Types.Mixed} | ||
// }); | ||
// schema.plugin(krkDbMongoosePluginsPassword, { passwordField: 'password' }); | ||
// schema.plugin($mongooseCreatedmodified.createdModifiedPlugin); | ||
// schema.methods.getSafely = getSafely; | ||
// schema.methods.updateLoginInfo = updateLoginInfo; | ||
// schema.statics.verifyAccount = verifyAccount; | ||
// schema.statics.invalidateAccount = invalidateAccount; | ||
// schema.statics.validateByAdmin = validateByAdmin; | ||
// return $mongoose.model('User', schema); | ||
function getSafely() { | ||
@@ -62,2 +119,61 @@ var userObj = this.toObject(); | ||
function sendVerificationEmail(config) { | ||
if (!( | ||
config.apiUrl | ||
&& config.apiUrlPrefix | ||
&& config.verifyAccountEmailTmpl | ||
&& config.emailSmtp | ||
&& config.emailAddress | ||
)) { | ||
throw new Error('Invalid arguments'); | ||
} | ||
var verifyAccountRoute = '/' + config.apiUrlPrefix + '/authorize/verifyAccount'; | ||
var verifyUrl = [ | ||
config.apiUrl, | ||
verifyAccountRoute, | ||
'?token=', | ||
this.validationToken | ||
].join(''); | ||
var emailTemplate = config.verifyAccountEmailTmpl({ | ||
verifyUrl: verifyUrl, | ||
user: this, | ||
apiUrl: config.apiUrl | ||
}); | ||
return krkNotificationsEmail.send(emailTemplate, { | ||
emailSmtp: config.emailSmtp, | ||
emailName: config.emailName, | ||
emailAddress: config.emailAddress | ||
}); | ||
} | ||
function sendResetPasswordEmail(config) { | ||
if (!( | ||
config.appUrl | ||
&& config.name | ||
&& config.password | ||
&& config.resetPasswordEmailTmpl | ||
&& config.emailSmtp | ||
&& config.emailAddress | ||
)) { | ||
throw new Error('Invalid arguments'); | ||
} | ||
var emailTemplate = config.resetPasswordEmailTmpl({ | ||
password: config.password, | ||
user: this, | ||
name: config.name, | ||
appUrl: config.appUrl | ||
}); | ||
return krkNotificationsEmail.send(emailTemplate, { | ||
emailSmtp: config.emailSmtp, | ||
emailName: config.emailName, | ||
emailAddress: config.emailAddress | ||
}) | ||
} | ||
function invalidateAccount(id, validationToken) { | ||
@@ -64,0 +180,0 @@ var q = { |
@@ -10,3 +10,3 @@ 'use strict'; | ||
function send(opts, config) { | ||
if (!(config.EMAIL_SMTP && config.EMAIL_NAME && config.EMAIL_ADDRESS)) { | ||
if (!(config.emailSmtp && config.emailAddress)) { | ||
throw new Error('Invalid arguments'); | ||
@@ -18,7 +18,21 @@ } | ||
var transporter = $nodemailer.createTransport(config.EMAIL_SMTP); | ||
var ma = config.emailSmtp; | ||
// var ma = { | ||
// host: "smtp-mail.outlook.com", // hostname | ||
// secureConnection: false, // TLS requires secureConnection to be false | ||
// port: 587, // port for secure SMTP | ||
// auth: { | ||
// user: "info@wiregoose.com", | ||
// pass: "MikroMouPony!@#" | ||
// }, | ||
// tls: { | ||
// ciphers:'SSLv3' | ||
// } | ||
// }; | ||
var from = config.EMAIL_NAME ? '"' + config.EMAIL_NAME + '" <' + config.EMAIL_ADDRESS + '>' | ||
: config.EMAIL_ADDRESS; | ||
var transporter = $nodemailer.createTransport(ma); | ||
var from = config.emailName ? '"' + config.emailName + '" <' + config.emailAddress + '>' | ||
: config.emailAddress; | ||
var mailOptions = { | ||
@@ -36,2 +50,2 @@ from, // sender address | ||
}); | ||
}); |
@@ -27,6 +27,6 @@ 'use strict'; | ||
&& config.apiUrl | ||
&& config.EMAIL_SMTP | ||
&& config.EMAIL_NAME | ||
&& config.EMAIL_ADDRESS | ||
&& config.name)) { | ||
&& config.name | ||
&& config.emailSmtp | ||
&& config.emailAddress | ||
)) { | ||
throw new Error('Invalid arguments'); | ||
@@ -36,2 +36,4 @@ } | ||
config.adminValidationOnSignup = config.adminValidationOnSignup || true; | ||
config.verifyAccountEmailTmpl = config.verifyAccountEmailTmpl || getDefaultVerificationEmail; | ||
config.resetPasswordEmailTmpl = config.resetPasswordEmailTmpl || getDefaultResetPasswordEmail; | ||
@@ -94,11 +96,21 @@ app.post('/' + config.apiUrlPrefix + '/authorize/signup', [ | ||
function middlewareSignupParameterValidator(req, res, next) { | ||
var validationOpts = [ | ||
{path: 'name', value: req.body.name, onValidate: function(v) { return res.locals.params.name = v;}}, | ||
{path: 'email', value: req.body.email, onValidate: function(v) { return res.locals.params.email = v;}}, | ||
{path: 'password', value: req.body.password, onValidate: function(v) { return res.locals.params.password = v;}}, | ||
{path: 'phone', value: req.body.phone, onValidate: function(v) { return res.locals.params.phone = v;}}, | ||
{path: 'preferences', value: req.body.preferences, onValidate: function(v) { return res.locals.params.preferences = v;}} | ||
{path: 'lang', value: req.body.lang, onValidate: function(v) { return res.locals.params.lang = v;}} | ||
]; | ||
// If we marked it as non-required in the schema | ||
if (!validationOpts[0].value) { | ||
res.locals.errors.add('INVALID_PARAMS', ['invalid password']); | ||
return next(true); | ||
} | ||
const pass = validationOpts[1].value; | ||
if (!(_.isString(pass) && pass.length >= 6)) { | ||
res.locals.errors.add('INVALID_PARAMS', ['invalid email address']); | ||
return next(true); | ||
} | ||
krkParameterValidator.modelPartialValidator(krkModelsUser, validationOpts) | ||
@@ -114,3 +126,3 @@ .then(function() { return next(); }) | ||
var validationOpts = [ | ||
{path: 'name', value: req.body.name, onValidate: function(v) { return res.locals.params.name = v;}}, | ||
{path: 'email', value: req.body.email, onValidate: function(v) { return res.locals.params.email = v;}}, | ||
{path: 'password', value: req.body.password, onValidate: function(v) { return res.locals.params.password = v;}} | ||
@@ -144,60 +156,63 @@ ]; | ||
function middlewareSignUpController(req, res, next) { | ||
q.promisify(function(cb) { return $crypto.randomBytes(32, cb); }) | ||
krkModelsUser.findOne({email: res.locals.params.email}) | ||
.then(user => { | ||
if (user) { | ||
res.locals.errors.add('ALREADY_EXIST'); | ||
throw new Error(); | ||
} | ||
}) | ||
.then(() => q.promisify(function(cb) { return $crypto.randomBytes(32, cb); }) | ||
.catch(function(reason) { | ||
res.locals.errors.add('NOT_ENOUGH_ENTROPY', reason); | ||
next(true); | ||
}) | ||
throw new Error(); | ||
})) | ||
.then(function(validationToken) { | ||
return new krkModelsUser({ | ||
const userObj = { | ||
validationToken: validationToken.toString('hex'), | ||
validationExpiresAt: new Date(), | ||
email: res.locals.params.email, | ||
name: res.locals.params.name, | ||
password: res.locals.params.password, | ||
phone: res.locals.params.phone, | ||
validatedByAdmin: config.adminValidationOnSignup, | ||
role: 'USER', | ||
preferences: res.locals.params.preferences | ||
}); | ||
lang: res.locals.params.lang, | ||
role: 'USER' | ||
}; | ||
if (config.adminValidationOnSignup) { | ||
userObj.validatedByAdmin = false; | ||
} | ||
return new krkModelsUser(userObj); | ||
}) | ||
.then(function(user) { | ||
if (process.env.UNIT_TEST) { | ||
krkLogger.info('send mock verification email to ' + user.name); | ||
return user; | ||
} | ||
var emailTemplate = krkRoutersAuthorizeVerifyAccountEmailTmpl.template({ | ||
verifyAccountRoute: verifyAccountRoute, | ||
user: user, | ||
name: config.name, | ||
apiUrl: config.apiUrl | ||
}); | ||
return krkNotificationsEmail.send(emailTemplate, { | ||
EMAIL_SMTP: config.EMAIL_SMTP, | ||
EMAIL_NAME: config.EMAIL_NAME, | ||
EMAIL_ADDRESS: config.EMAIL_ADDRESS | ||
return user.sendVerificationEmail({ | ||
apiUrl: config.apiUrl, | ||
apiUrlPrefix: config.apiUrlPrefix, | ||
verifyAccountEmailTmpl: config.verifyAccountEmailTmpl, | ||
emailSmtp: config.emailSmtp, | ||
emailName: config.emailName, | ||
emailAddress: config.emailAddress | ||
}) | ||
.catch(function(reason) { | ||
res.locals.errors.add('EMAIL_FAIL', reason.errors || reason); | ||
next(true); | ||
}) | ||
.then(function() { return user; }) | ||
}) | ||
.then(function(newUser) { | ||
return newUser.save() | ||
.catch(function(reason) { | ||
res.locals.errors.add('EMAIL_FAIL', reason.errors || reason); | ||
next(true); | ||
if (reason.code === 11000) { | ||
res.locals.errors.add('ALREADY_EXIST'); | ||
} else { | ||
res.locals.errors.add('DB_ERROR', reason.errors || reason); | ||
} | ||
throw new Error(); | ||
}) | ||
.then(function() { return user; }); | ||
}) | ||
.then(function(newUser) { | ||
return newUser.save(); | ||
res.locals.data = newUser.getSafely(); | ||
return next(); | ||
}) | ||
.catch(function(reason) { | ||
if (reason.code === 11000) { | ||
res.locals.errors.add('ALREADY_EXIST'); | ||
} else { | ||
res.locals.errors.add('DB_ERROR', reason.errors || reason); | ||
} | ||
next(true); | ||
}) | ||
.then(function(newUser) { | ||
return res.locals.data = newUser.getSafely(); | ||
}) | ||
.then(function() { return next(); }); | ||
.catch(function() { return next(true); }); | ||
} | ||
function middlewareLoginController(req, res, next) { | ||
krkModelsUser.findOne({name: res.locals.params.name}) | ||
krkModelsUser.findOne({email: res.locals.params.email}) | ||
.catch(function(reason) { return error('DB_ERROR', reason); }) | ||
@@ -209,3 +224,3 @@ .then(function(user) { | ||
return user.comparePassword(req.body.password) | ||
return user.comparePassword(res.locals.params.password) | ||
.then(function(isEqual) { | ||
@@ -236,3 +251,3 @@ res.locals.data = krkMiddlewarePermissions.createJWT(user); | ||
res.locals.redirect = config.appUrl + '/#/?validated=' + updated._id + '?email=' + updated.email; | ||
res.locals.redirect = config.appUrl + '?validated=' + updated.email; | ||
next(); | ||
@@ -278,47 +293,62 @@ }); | ||
krkModelsUser.findOne({email: res.locals.params.email}) | ||
.catch(function(reason) { | ||
res.locals.errors.add('DB_ERROR', reason); | ||
return next(true); | ||
.catch(function(reason) { | ||
res.locals.errors.add('DB_ERROR', reason); | ||
throw new Error(); | ||
}) | ||
.then(user => { | ||
if (!user) { | ||
return next(); | ||
} | ||
q.promisify(function(cb) { return $crypto.randomBytes(16, cb); }) | ||
.catch(function(reason) { | ||
res.locals.errors.add('NOT_ENOUGH_ENTROPY', reason); | ||
throw new Error(); | ||
}) | ||
.then(function(newPassword) { | ||
user.password = newPassword.toString('hex'); | ||
return user.sendResetPasswordEmail({ | ||
password: user.password, | ||
name: config.name, | ||
appUrl: config.appUrl, | ||
resetPasswordEmailTmpl: config.resetPasswordEmailTmpl, | ||
emailSmtp: config.emailSmtp, | ||
emailName: config.emailName, | ||
emailAddress: config.emailAddress | ||
}) | ||
.catch(function(reason) { | ||
res.locals.errors.add('EMAIL_FAIL', reason.errors || reason); | ||
throw new Error(); | ||
}); | ||
}) | ||
.then(user => { | ||
if (!user) { | ||
return next(); | ||
} | ||
let newPassword = $crypto.randomBytes(16).toString('hex'); | ||
q.resolve() | ||
.then(function() { | ||
user.password = newPassword; | ||
return user.save(); | ||
}) | ||
.then(function() { | ||
return user.save() | ||
.catch(function(reason) { | ||
res.locals.errors.add('DB_ERROR', reason.errors || reason); | ||
next(true); | ||
throw new Error(); | ||
}) | ||
.then(function(user) { | ||
res.locals.data = user.getSafely(); | ||
var emailTemplate = krkRoutersAuthorizeResetPasswordEmailTmpl.template({ | ||
password: newPassword, | ||
user: user, | ||
name: config.name, | ||
appUrl: config.appUrl | ||
}); | ||
return krkNotificationsEmail.send(emailTemplate, { | ||
EMAIL_SMTP: config.EMAIL_SMTP, | ||
EMAIL_NAME: config.EMAIL_NAME, | ||
EMAIL_ADDRESS: config.EMAIL_ADDRESS | ||
}) | ||
.catch(function(reason) { | ||
res.locals.errors.add('EMAIL_FAIL', reason.errors || reason); | ||
next(true); | ||
}); | ||
}) | ||
.catch(function(reason) { | ||
res.locals.errors.add('UNEXPECTED', reason.errors || reason); | ||
next(true); | ||
}) | ||
.then(function() { return next(); }); | ||
}) | ||
.then(function() { return next(); }) | ||
.catch(function(reason) { return next(true); }) | ||
}) | ||
} | ||
function getDefaultVerificationEmail(opts) { | ||
return krkRoutersAuthorizeVerifyAccountEmailTmpl.template({ | ||
verifyUrl: opts.verifyUrl, | ||
user: opts.user, | ||
apiUrl: opts.apiUrl | ||
}); | ||
} | ||
function getDefaultResetPasswordEmail(opts) { | ||
return krkRoutersAuthorizeResetPasswordEmailTmpl.template({ | ||
password: opts.newPassword, | ||
user: opts.user, | ||
name: opts.name, | ||
appUrl: opts.appUrl | ||
}); | ||
} | ||
} | ||
}); |
@@ -19,3 +19,3 @@ 'use strict'; | ||
<h1>' + config.name + '</h1>\ | ||
<h3>Γειά σας ' + config.user.name + '</h3>\ | ||
<h3>Γειά σας ' + config.user.email + '</h3>\ | ||
<p>Ο νέος σας προσωρινός κωδικό είναι ' + config.password + '</p>\ | ||
@@ -22,0 +22,0 @@ <p>Θα ήταν ασφαλέστερο αν <a href="' + settingsUrl + '">αλλάζατε τον προσωρινό σας κωδικό</a></p>\ |
'use strict'; | ||
KlarkModule(module, 'krkRoutersAuthorizeVerifyAccountEmailTmpl', function(config) { | ||
KlarkModule(module, 'krkRoutersAuthorizeVerifyAccountEmailTmpl', function() { | ||
@@ -10,12 +10,11 @@ return { | ||
function template(config) { | ||
if (!(config && config.user && config.verifyAccountRoute && config.name && config.apiUrl)) { | ||
if (!(config && config.user && config.verifyUrl && config.apiUrl)) { | ||
throw new Error('Invalid arguments'); | ||
} | ||
var subject = config.name + ' Πιστοποιήστε τον λογαριασμό σας'; | ||
var subject = 'Πιστοποιήστε τον λογαριασμό σας'; | ||
var verifyUrl = [config.apiUrl, config.verifyAccountRoute, '?token=', config.user.validationToken].join(''); | ||
var content = '\ | ||
Κε/Κα ' + config.name + ',\ | ||
<p>Ευχαριστούμε για την εγγραφή σας στην εφαρμογή <strong>RFS-iSAFE WebApp!</strong><br>\ | ||
Παρακαλούμε πατήστε <a href="' + verifyUrl + '">εδώ</a> για να ολοκληρωθεί η εγγραφή σας.</p>\ | ||
Κε/Κα ' + config.user.email + ',\ | ||
<p>Ευχαριστούμε για την εγγραφή σας στην εφαρμογή<br>\ | ||
Παρακαλούμε πατήστε <a href="' + config.verifyUrl + '">εδώ</a> για να ολοκληρωθεί η εγγραφή σας.</p>\ | ||
Με εκτίμηση, \ | ||
@@ -22,0 +21,0 @@ '; |
@@ -11,3 +11,2 @@ 'use strict'; | ||
krkCrudGenerator, | ||
krkNotificationsEmail, | ||
krkMiddlewareParameterValidator, | ||
@@ -24,7 +23,14 @@ krkMiddlewareResponse, | ||
function register(app, config) { | ||
if (!(app && config && config.apiUrl && config.apiUrlPrefix && config.name | ||
&& config.EMAIL_SMTP && config.EMAIL_NAME && config.EMAIL_ADDRESS)) { | ||
if (!(app | ||
&& config | ||
&& config.apiUrl | ||
&& config.apiUrlPrefix | ||
&& config.emailSmtp | ||
&& config.emailAddress | ||
)) { | ||
throw new Error('Invalid arguments'); | ||
} | ||
config.verifyAccountEmailTmpl = config.verifyAccountEmailTmpl || getDefaultVerificationEmail; | ||
const crudOpts = { | ||
@@ -50,5 +56,3 @@ model: krkModelsUser, | ||
var possibleValues = [ | ||
'name', | ||
'email', | ||
'phone', | ||
'newPassword', | ||
@@ -134,10 +138,2 @@ 'oldPassword', | ||
if (_.find(fulfilled, function(v) { return v.value === 'name'; })) { | ||
user.name = res.locals.params.name; | ||
} | ||
if (_.find(fulfilled, function(v) { return v.value === 'phone'; })) { | ||
user.phone = res.locals.params.phone; | ||
} | ||
if (_.find(fulfilled, function(v) { return v.value === 'role'; })) { | ||
@@ -174,3 +170,4 @@ if (res.locals.user.role !== 'ADMIN') { | ||
return q.promisify(function(cb) { | ||
return $crypto.randomBytes(32, cb); }) | ||
return $crypto.randomBytes(32, cb); | ||
}) | ||
.catch(function(reason) { | ||
@@ -186,15 +183,11 @@ return res.locals.errors.add('NOT_ENOUGH_ENTROPY', reason); | ||
.then(function(updatedUser) { | ||
var verifyAccountRoute = '/' + config.apiUrlPrefix + '/authorize/verifyAccount'; | ||
updatedUser.email = res.locals.params.email | ||
var emailTemplate = krkRoutersAuthorizeVerifyAccountEmailTmpl.template({ | ||
verifyAccountRoute: verifyAccountRoute, | ||
user: updatedUser, | ||
name: config.name, | ||
apiUrl: config.apiUrl | ||
}); | ||
return krkNotificationsEmail.send(emailTemplate, { | ||
EMAIL_SMTP: config.EMAIL_SMTP, | ||
EMAIL_NAME: config.EMAIL_NAME, | ||
EMAIL_ADDRESS: config.EMAIL_ADDRESS | ||
}) | ||
updatedUser.email = res.locals.params.email; | ||
return updatedUser.sendVerificationEmail({ | ||
apiUrl: config.apiUrl, | ||
apiUrlPrefix: config.apiUrlPrefix, | ||
verifyAccountEmailTmpl: config.verifyAccountEmailTmpl, | ||
emailSmtp: config.emailSmtp, | ||
emailName: config.emailName, | ||
emailAddress: config.emailAddress | ||
}) | ||
.catch(function(reason) { | ||
@@ -227,3 +220,11 @@ return res.locals.errors.add('EMAIL_FAIL', reason.errors || reason); | ||
} | ||
function getDefaultVerificationEmail(opts) { | ||
return krkRoutersAuthorizeVerifyAccountEmailTmpl.template({ | ||
verifyUrl: opts.verifyUrl, | ||
user: opts.user, | ||
apiUrl: opts.apiUrl | ||
}); | ||
} | ||
} | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81823
2057