Update auth.js
This commit is contained in:
parent
1588e4f861
commit
b054e3b310
1 changed files with 0 additions and 32 deletions
|
@ -64,36 +64,4 @@ router.post('/logout', function(req, res, next) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/signup', function(req, res, next) {
|
|
||||||
res.render('signup');
|
|
||||||
});
|
|
||||||
|
|
||||||
router.post('/signup', function(req, res, next) {
|
|
||||||
var salt = crypto.randomBytes(16);
|
|
||||||
crypto.pbkdf2(req.body.password, salt, 310000, 32, 'sha256', function(err, hashedPassword) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
db.run('INSERT INTO users (username, hashed_password, salt) VALUES (?, ?, ?)', [
|
|
||||||
req.body.username,
|
|
||||||
hashedPassword,
|
|
||||||
salt
|
|
||||||
], function(err) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
var user = {
|
|
||||||
id: this.lastID,
|
|
||||||
username: req.body.username
|
|
||||||
};
|
|
||||||
req.login(user, function(err) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
res.redirect('/');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue