klark-js-plugins
Advanced tools
Comparing version 1.0.13 to 1.0.14
@@ -0,0 +0,0 @@ { |
{ | ||
"vsicons.presets.angular": false | ||
} |
{ | ||
"name": "klark-js-plugins", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "Plugin modules for KlarkJS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
krkRoutersAuthorizeVerifyAccountEmailTmpl, | ||
krkRoutersAuthorizeResetPasswordEmailTmpl, | ||
krkNotificationsEmail, | ||
@@ -73,2 +74,9 @@ krkMiddlewareResponse, | ||
app.post('/' + config.apiUrlPrefix + '/authorize/resetPassword', [ | ||
krkMiddlewarePermissions.check('FREE'), | ||
middlewareResetPasswordValidator, | ||
middlewareResetPasswordController, | ||
krkMiddlewareResponse.success | ||
]); | ||
function middlewareVerifyAccountParameterValidator(req, res, next) { | ||
@@ -121,2 +129,14 @@ var validationOpts = [ | ||
function middlewareResetPasswordValidator(req, res, next) { | ||
var validationOpts = [ | ||
{path: 'email', value: req.body.email, onValidate: v => res.locals.params.email = v} | ||
]; | ||
krkParameterValidator.modelPartialValidator(krkModelsUser, validationOpts) | ||
.then(function() { return next(); }) | ||
.catch(function(reason) { | ||
res.locals.errors.add('INVALID_PARAMS', reason); | ||
next(true); | ||
}); | ||
} | ||
function middlewareSignUpController(req, res, next) { | ||
@@ -251,4 +271,53 @@ q.promisify(function(cb) { return $crypto.randomBytes(32, cb); }) | ||
} | ||
function middlewareResetPasswordController(req, res, next) { | ||
krkModelsUser.findOne({email: res.locals.params.email}) | ||
.catch(function(reason) { | ||
res.locals.errors.add('DB_ERROR', reason); | ||
return next(true); | ||
}) | ||
.then(user => { | ||
if (!user) { | ||
return next(); | ||
} | ||
q.resolve() | ||
.then(() => ({ | ||
user, | ||
token: $crypto.randomBytes(8) | ||
})) | ||
.then(function({user, token}) { | ||
user.password = token.toString('hex'); | ||
return user.save(); | ||
}) | ||
.catch(function(reason) { | ||
res.locals.errors.add('DB_ERROR', reason.errors || reason); | ||
next(true); | ||
}) | ||
.then(function(user) { | ||
res.locals.data = user.getSafely(); | ||
var emailTemplate = krkRoutersAuthorizeResetPasswordEmailTmpl.template({ | ||
password: user.password, | ||
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(); }); | ||
}) | ||
} | ||
} | ||
}); |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ # klark plugins |
Sorry, the diff of this file is not supported yet
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
78943
34
1899