Add initial server setup

This commit is contained in:
Kevin Thomas
2021-07-20 22:44:00 -07:00
parent 5585d81690
commit 413925131d
11 changed files with 1572 additions and 357 deletions

37
server/routes/users.js Normal file
View File

@@ -0,0 +1,37 @@
const express = require('express');
const crypto = require('crypto');
const db = require('../db');
const router = express.Router();
router.get('/new', function(req, res, next) {
res.render('signup');
});
router.post('/', function(req, res, next) {
const salt = crypto.randomBytes(16);
crypto.pbkdf2(req.body.password, salt, 10000, 32, 'sha256', function(err, hashedPassword) {
if (err) { return next(err); }
db.run('INSERT INTO users (username, hashed_password, salt, name) VALUES (?, ?, ?, ?)', [
req.body.username,
hashedPassword,
salt,
req.body.name
], function(err) {
if (err) { return next(err); }
const user = {
id: this.lastID.toString(),
username: req.body.username,
displayName: req.body.name
};
req.login(user, function(err) {
if (err) { return next(err); }
res.redirect('/');
});
});
});
});
module.exports = router;