- Mailer setup

This commit is contained in:
2019-08-20 08:39:10 -04:00
parent dce868f2ac
commit 697b04a55b
9 changed files with 203 additions and 44 deletions

View File

@@ -5,13 +5,13 @@ const User = require('../models/user');
module.exports = function (server, auth) {
const { passport } = auth;
server.post('/signup', (req, res, next) => {
server.post('/signup', auth.basic, (req, res, next) => {
const { body: { user = null } = {} } = req;
let errors = {};
let errorCount = 0;
if (!user) {
errors.user = 'is required - can\'t make something from nothing...'';
errors.user = `is required - can't make something from nothing...`;
errorCount++;
}
@@ -21,13 +21,13 @@ module.exports = function (server, auth) {
User.register(user, (err, user, info) => {
if (err) {
next(err);
return next(err);
}
if (info) {
res.send(200, {
success: false,
nextSteps: 'Please fix the problems indicated and try again.'
nextSteps: 'Please fix the problems indicated and try again.',
...info
});
@@ -36,9 +36,44 @@ module.exports = function (server, auth) {
res.send(200, {
success: true,
nextSteps: 'Check your email for our confirmation email, you will not be able to login without confirming.'
nextSteps: 'Check your email for our confirmation email, you will not be able to login without confirming.',
});
next();
});
});
server.get('/signup/confirm/:token([A-Za-z0-9_]+\.{3})', (req, res, next) => {
const { token } = req.params;
if (!token) {
return next(
new errors.InvalidContentError('A confirmation token was not provided.'),
);
}
User.verifyTokenAndConfirmRegistration(reset_token, password, (err, user, info) => {
if (err) {
console.error(err);
return next(
new errors.InvalidContentError(err),
);
}
if (!user) {
console.error(err);
res.send({
success: false,
info: `Account registration confirmation failed. ${info}`,
});
return next();
}
res.send({
success: true,
info: 'New account registration confirmed.',
...user.toAuthJSON()
});
next();
});
});