From 5b23a4a9db4e57e70058aede9241890096d9c53a Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Sun, 11 Jun 2017 17:12:28 +0200 Subject: [PATCH] save and request usernames in lower case for app-user --- api/routes/authenticate.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/routes/authenticate.js b/api/routes/authenticate.js index f778c08..e93baa5 100644 --- a/api/routes/authenticate.js +++ b/api/routes/authenticate.js @@ -47,7 +47,7 @@ authenticate.route('/') let authCheck = (username, password, res) => { const deferred = Q.defer(); - AppUserModel.findOne({username: username}).populate('squad').exec((err, user) => { + AppUserModel.findOne({username: username.toLowerCase()}).populate('squad').exec((err, user) => { if (err) deferred.reject(err.name + ': ' + err.message); const diff = 7 * 60 * 24; // time till expiration [minutes] @@ -96,7 +96,7 @@ let create = (userParam) => { // validation AppUserModel.findOne( - {username: userParam.username}, + {username: userParam.username.toLowerCase()}, (err, user) => { if (err) deferred.reject(err.name + ': ' + err.message); @@ -114,6 +114,7 @@ let create = (userParam) => { // add hashed password to user object user.password = bcrypt.hashSync(userParam.password, 10); + user.username = user.username.toLowerCase(); const newUser = new AppUserModel(user); newUser.save((err, doc) => {