- Initial commit... A DB, some routes, and basic authentication routines...
This commit is contained in:
42
routes/signup.js
Normal file
42
routes/signup.js
Normal file
@@ -0,0 +1,42 @@
|
||||
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.'
|
||||
})
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user