Trim username
This commit is contained in:
parent
22b536454b
commit
19b660f024
3 changed files with 4 additions and 3 deletions
1
index.js
1
index.js
|
@ -18,6 +18,7 @@ const db = new PouchDB(config.dbUrl);
|
||||||
|
|
||||||
passport.use('local', new LocalStrategy(
|
passport.use('local', new LocalStrategy(
|
||||||
(username, password, done) => {
|
(username, password, done) => {
|
||||||
|
username = username.trim();
|
||||||
db.get(username)
|
db.get(username)
|
||||||
.then(doc => {
|
.then(doc => {
|
||||||
bcrypt.compare(password, doc.password, (err, correct) => {
|
bcrypt.compare(password, doc.password, (err, correct) => {
|
||||||
|
|
|
@ -19,12 +19,12 @@ module.exports = (db) => {
|
||||||
bcrypt.hash(req.body.newUserPassword, null, null, async (err, newUserPasswordHash) => {
|
bcrypt.hash(req.body.newUserPassword, null, null, async (err, newUserPasswordHash) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
await db.put({
|
await db.put({
|
||||||
_id: req.body.newUserUsername,
|
_id: req.body.newUserUsername.trim(),
|
||||||
password: newUserPasswordHash,
|
password: newUserPasswordHash,
|
||||||
admin: false,
|
admin: false,
|
||||||
wishlist: []
|
wishlist: []
|
||||||
});
|
});
|
||||||
req.flash('success', `Successfully added user ${req.body.newUserUsername}!`);
|
req.flash('success', `Successfully added user ${req.body.newUserUsername.trim()}!`);
|
||||||
res.redirect('/admin-settings');
|
res.redirect('/admin-settings');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,7 @@ module.exports = (db) => {
|
||||||
bcrypt.hash(req.body.adminPassword, null, null, (err, adminPasswordHash) => {
|
bcrypt.hash(req.body.adminPassword, null, null, (err, adminPasswordHash) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
db.put({
|
db.put({
|
||||||
_id: req.body.adminUsername,
|
_id: req.body.adminUsername.trim(),
|
||||||
password: adminPasswordHash,
|
password: adminPasswordHash,
|
||||||
admin: true,
|
admin: true,
|
||||||
wishlist: []
|
wishlist: []
|
||||||
|
|
Loading…
Reference in a new issue