const errors = require('restify-errors'); const User = require('../models/user'); module.exports = function (server, auth) { const { passport } = auth; server.post('/signup', (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...''; errorCount++; } if (errorCount) { return res.send(422, { errors }); } User.register(user, (err, user, info) => { if (err) { next(err); } if (info) { res.send(200, { registrationSuccess: false, nextSteps: 'Please fix the problems indicated and try again.' ...info }); return next(); } res.send(200, { registrationSuccess: true, nextSteps: 'Check your email for our confirmation email, you will not be able to login without confirming.' }) }); }); };