Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #656 from fauria/0.4.0
Browse files Browse the repository at this point in the history
Use validator.js for email and password length validation.
  • Loading branch information
lirantal committed Jul 17, 2015
2 parents 32c12bb + a23290b commit a1355a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 11 additions & 4 deletions modules/users/server/models/user.server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
crypto = require('crypto');
crypto = require('crypto'),
validator = require('validator');

/**
* A Validation function for local strategy properties
Expand All @@ -18,7 +19,14 @@ var validateLocalStrategyProperty = function(property) {
* A Validation function for local strategy password
*/
var validateLocalStrategyPassword = function(password) {
return (this.provider !== 'local' || (password && password.length > 6));
return (this.provider !== 'local' || validator.isLength(password, 6));
};

/**
* A Validation function for local strategy email
*/
var validateLocalStrategyEmail = function(email) {
return ((this.provider !== 'local' && !this.updated) || validator.isEmail(email));
};

/**
Expand All @@ -45,8 +53,7 @@ var UserSchema = new Schema({
type: String,
trim: true,
default: '',
validate: [validateLocalStrategyProperty, 'Please fill in your email'],
match: [/.+\@.+\..+/, 'Please fill a valid email address']
validate: [validateLocalStrategyEmail, 'Please fill a valid email address']
},
username: {
type: String,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@
"passport": "~0.2.2",
"passport-facebook": "^2.0.0",
"passport-github": "~0.1.5",
"passport-paypal-openidconnect": "^0.1.1",
"passport-google-oauth": "~0.2.0",
"passport-linkedin": "~0.1.3",
"passport-local": "^1.0.0",
"passport-paypal-openidconnect": "^0.1.1",
"passport-twitter": "^1.0.2",
"serve-favicon": "^2.3.0",
"socket.io": "^1.3.5",
"swig": "^1.4.2"
"swig": "^1.4.2",
"validator": "^3.41.2"
},
"devDependencies": {
"grunt-concurrent": "^2.0.0",
Expand Down

0 comments on commit a1355a0

Please sign in to comment.