here's code: changed something, , when try create new user used email address fails due timeout limit exceeded...
joi.validate(req.body, schema, { stripunknown: true }, (err) => { if (err) { let message = err.details[0].message; if (message.substr(1,4) === "user") { message = '"username" must contain alpha-numeric characters'; } if (req.body.username === 'password') { message = "invalid username"; } res.status(400).send({ error: message }) } else { if (!req.body.username) { res.status(400).send({ error: '"username" required' }); } else if (!req.body.primary_email) { res.status(400).send({ error: '"primary_email" required' }); } else if (!req.body.password) { res.status(400).send({ error: '"password" required' }); } else { let user = new user(req.body); //change this? user.save(err => { if (err) { //error username/primary_email in use if (err.code === 11000) { if (err.message.indexof('username_1') !== -1) res.status(400).send({ error: 'username in use' }); if (err.message.indexof('primary_email_!') !== -1) res.status(400).send({ error: 'email address in use' }); } } else { // let newsession = req.session; // newsession.username = req.body.username; // req.session.save(); req.session.regenerate(function(){ req.session.user = user; res.status(201).send({ username: req.body.username, primary_email: req.body.primary_email, }); }); } } ) } } })
its making me add more details yeah
Comments
Post a Comment