diff options
| author | Adam Soltys <[email protected]> | 2017-04-10 22:42:45 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2017-04-10 22:42:45 -0700 |
| commit | b7a4332e9487659532ea50cd8063d0cd44011dce (patch) | |
| tree | 3788725330ac7d3bdfb521f4a682d54b044c19eb | |
| parent | 5e9334ec60e75b3ee3bc539eedc53fa4e0366e29 (diff) | |
| download | coinos-server-b7a4332e9487659532ea50cd8063d0cd44011dce.tar.gz coinos-server-b7a4332e9487659532ea50cd8063d0cd44011dce.zip | |
create user validation
| -rw-r--r-- | routes/users.js | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/routes/users.js b/routes/users.js index 5968a54c..8f68b760 100644 --- a/routes/users.js +++ b/routes/users.js @@ -49,15 +49,17 @@ module.exports = (sessions) => { create: function(req, res) { const userkey = "user:" + req.body.username - db.hgetallAsync(userkey).then((err, obj) => { + db.hgetallAsync(userkey).then((obj) => { if (obj) { - res.status(400).json({ message: 'User exists' }) - return + error = { message: 'User exists' } + res.status(400).json(error) + throw error } - + }).then(() => { if (req.body.passconfirm !== req.body.password) { - res.status(400).json({ message: 'Passwords must match' }) - return + error = { message: 'Passwords must match' } + res.status(400).json(error) + throw error } bcrypt.hash(req.body.password, 12, function(err, hash) { @@ -75,10 +77,7 @@ module.exports = (sessions) => { require('crypto').randomBytes(48, function(ex, buf) { const token = buf.toString('base64').replace(/\//g, '').replace(/\+/g, '') db.set("token:" + token, req.body.username) - host = req.hostname - if (host === 'localhost') { - host += ':' + req.port - } + host = req.get('Host') url = req.protocol + "://" + host + "/verify/" + token res.render('users/welcome', { user: req.body.username.toLowerCase(), @@ -109,7 +108,7 @@ module.exports = (sessions) => { }) }) }) - }) + }).catch((e) => {}) }, update: function(req, res) { if (req.body.password === '') { |
