From a23290b46ee3d3c28d54d04f4e36202083542b69 Mon Sep 17 00:00:00 2001 From: git-admin Date: Fri, 17 Jul 2015 09:27:16 +0200 Subject: [PATCH] Use validator.js for email validation --- modules/users/server/models/user.server.model.js | 15 +++++++++++---- package.json | 5 +++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/users/server/models/user.server.model.js b/modules/users/server/models/user.server.model.js index bf5743c4fb..3f2225e6f1 100644 --- a/modules/users/server/models/user.server.model.js +++ b/modules/users/server/models/user.server.model.js @@ -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 @@ -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)); }; /** @@ -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, diff --git a/package.json b/package.json index 4487b15c00..96959320a3 100644 --- a/package.json +++ b/package.json @@ -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",