Skip to content

Commit

Permalink
fix trim and lowercase user username and email
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Aug 6, 2015
1 parent e995828 commit 8c7a9dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 8 additions & 0 deletions common/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ module.exports = function(User) {
// username should be unique
User.validatesUniquenessOf('username');

User.observe('before save', function({ instance: user }, next) {
if (user) {
user.username = user.username.trim().toLowerCase();
user.email = user.email.trim().toLowerCase();
}
next();
});

debug('setting up user hooks');
User.afterRemote('confirm', function(ctx) {
ctx.req.flash('success', {
Expand Down
13 changes: 7 additions & 6 deletions common/models/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"unique": true,
"sparse": true
}
},
"lowercase": true,
"trim": true
}
},
"password": {
"type": "string"
Expand Down Expand Up @@ -45,9 +43,12 @@
},
"username": {
"type": "string",
"lowercase": true,
"trim": true,
"require": true
"require": true,
"index": {
"mongodb": {
"unique": true
}
}
},
"bio": {
"type": "string",
Expand Down

0 comments on commit 8c7a9dd

Please sign in to comment.