Skip to content

Commit

Permalink
Merge pull request #123 from Gentlee/optimize-lowercase
Browse files Browse the repository at this point in the history
optimize username lowercasing
  • Loading branch information
saintedlama committed Mar 4, 2016
2 parents 167430e + 61e9462 commit 4b8bf63
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ module.exports = function(schema, options) {

schema.add(schemaFields);

schema.pre('save', function(next) {
// if specified, convert the username to lowercase
if (options.usernameLowerCase && this[options.usernameField]) {
this[options.usernameField] = this[options.usernameField].toLowerCase();
}
if (options.usernameLowerCase) {
schema.pre('save', function(next) {
if (this[options.usernameField]) {
this[options.usernameField] = this[options.usernameField].toLowerCase();
}

next();
});
next();
});
}

schema.methods.setPassword = function(password, cb) {
if (!password) {
Expand Down

0 comments on commit 4b8bf63

Please sign in to comment.