From 19b660f0247ef8482a6dc31804b0c02e783fd80a Mon Sep 17 00:00:00 2001 From: Wingysam Date: Mon, 3 Dec 2018 17:03:43 -0500 Subject: [PATCH] Trim username --- index.js | 1 + routes/adminSettings/index.js | 4 ++-- routes/setup/index.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index f2925cc..228e8aa 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ const db = new PouchDB(config.dbUrl); passport.use('local', new LocalStrategy( (username, password, done) => { + username = username.trim(); db.get(username) .then(doc => { bcrypt.compare(password, doc.password, (err, correct) => { diff --git a/routes/adminSettings/index.js b/routes/adminSettings/index.js index 896c1a7..48a4884 100644 --- a/routes/adminSettings/index.js +++ b/routes/adminSettings/index.js @@ -19,12 +19,12 @@ module.exports = (db) => { bcrypt.hash(req.body.newUserPassword, null, null, async (err, newUserPasswordHash) => { if (err) throw err; await db.put({ - _id: req.body.newUserUsername, + _id: req.body.newUserUsername.trim(), password: newUserPasswordHash, admin: false, wishlist: [] }); - req.flash('success', `Successfully added user ${req.body.newUserUsername}!`); + req.flash('success', `Successfully added user ${req.body.newUserUsername.trim()}!`); res.redirect('/admin-settings'); }); }); diff --git a/routes/setup/index.js b/routes/setup/index.js index bd0f043..9442b77 100644 --- a/routes/setup/index.js +++ b/routes/setup/index.js @@ -22,7 +22,7 @@ module.exports = (db) => { bcrypt.hash(req.body.adminPassword, null, null, (err, adminPasswordHash) => { if (err) throw err; db.put({ - _id: req.body.adminUsername, + _id: req.body.adminUsername.trim(), password: adminPasswordHash, admin: true, wishlist: []