Initial Commit

This commit is contained in:
Wingysam 2018-11-20 14:19:58 -05:00
commit f54d97e4a9
30 changed files with 2532 additions and 0 deletions

39
routes/setup/index.js Normal file
View file

@ -0,0 +1,39 @@
const bcrypt = require('bcrypt-nodejs')
const express = require('express');
module.exports = (db) => {
const router = express.Router();
router.get('/',
async (req, res) => {
const dbInfo = await db.info();
if (dbInfo.doc_count === 0) {
res.render('setup', { title: 'Setup' });
} else {
res.redirect('/');
}
}
);
router.post('/',
async (req, res) => {
const dbInfo = await db.info();
if (dbInfo.doc_count === 0) {
bcrypt.hash(req.body.adminPassword, null, null, (err, adminPasswordHash) => {
if (err) throw err;
db.put({
_id: req.body.adminUsername,
password: adminPasswordHash,
admin: true,
wishlist: []
})
res.redirect('/');
});
} else {
res.redirect('/');
}
}
);
return router;
}