Initial Commit
This commit is contained in:
commit
f54d97e4a9
30 changed files with 2532 additions and 0 deletions
39
routes/setup/index.js
Normal file
39
routes/setup/index.js
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue