Skip to content

Commit

Permalink
Force lower-case email on retrieve/create/update
Browse files Browse the repository at this point in the history
Fixes Login email address should be case-insensitive #2060
  • Loading branch information
taylortom committed Feb 8, 2022
1 parent 0d1be21 commit 65d83c2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/usermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ exports = module.exports = {
if (!user.email || 'string' !== typeof user.email) {
return callback(new UserEmailError('user email is required!'));
}

database.getDatabase(function(err, db){
if (err) {
return callback(err);
Expand All @@ -220,6 +219,8 @@ exports = module.exports = {
// user exists
return callback(new DuplicateUserError());
} else {
// ensure email is lower case
user.email = user.email.toLowerCase();
db.create('user', user, function (error, result) {
// Wrap the callback since we might want to alter the result
if (error) {
Expand Down Expand Up @@ -261,7 +262,9 @@ exports = module.exports = {
callback = options;
options = {};
}

if(search.email) {
search.email = search.email.toLowerCase();
}
database.getDatabase(function(err,db) {
db.retrieve('user', search, options, function (error, results) {
if (error) {
Expand Down Expand Up @@ -300,6 +303,9 @@ exports = module.exports = {
return callback(new Error('No matching user record found'));
}
database.getDatabase(function(err, db) {
if(update.email) {
updateEmail = update.email.toLowerCase();
}
if (update.email !== self.getCurrentUser().email) {
// email updated, verify the new email does not already exist
db.retrieve('user', { email: update.email }, function (error, results) {
Expand Down

0 comments on commit 65d83c2

Please sign in to comment.