diff --git a/core/client/validators/new-user.js b/core/client/validators/new-user.js new file mode 100644 index 0000000000..faaf3029ca --- /dev/null +++ b/core/client/validators/new-user.js @@ -0,0 +1,28 @@ +var NewUserValidator = Ember.Object.extend({ + check: function (model) { + var data = model.getProperties('name', 'email', 'password'), + validationErrors = []; + + if (!validator.isLength(data.name, 1)) { + validationErrors.push({ + message: 'Please enter a name.' + }); + } + + if (!validator.isEmail(data.email)) { + validationErrors.push({ + message: 'Invalid Email.' + }); + } + + if (!validator.isLength(data.password, 8)) { + validationErrors.push({ + message: 'Password must be at least 8 characters long.' + }); + } + + return validationErrors; + } +}); + +export default NewUserValidator; diff --git a/core/client/validators/setup.js b/core/client/validators/setup.js index 9f7de2af5c..ab5c74fd75 100644 --- a/core/client/validators/setup.js +++ b/core/client/validators/setup.js @@ -1,7 +1,9 @@ -var SetupValidator = Ember.Object.create({ +import NewUserValidator from 'ghost/validators/new-user'; + +var SetupValidator = NewUserValidator.extend({ check: function (model) { - var data = model.getProperties('blogTitle', 'name', 'email', 'password'), - validationErrors = []; + var data = model.getProperties('blogTitle'), + validationErrors = this._super(model); if (!validator.isLength(data.blogTitle, 1)) { validationErrors.push({ @@ -9,26 +11,8 @@ var SetupValidator = Ember.Object.create({ }); } - if (!validator.isLength(data.name, 1)) { - validationErrors.push({ - message: 'Please enter a name.' - }); - } - - if (!validator.isEmail(data.email)) { - validationErrors.push({ - message: 'Invalid Email.' - }); - } - - if (!validator.isLength(data.password, 8)) { - validationErrors.push({ - message: 'Password must be at least 8 characters long.' - }); - } - return validationErrors; } -}); +}).create(); export default SetupValidator; diff --git a/core/client/validators/signup.js b/core/client/validators/signup.js index 27745e8a0e..0e0a537719 100644 --- a/core/client/validators/signup.js +++ b/core/client/validators/signup.js @@ -1,28 +1,3 @@ -var SignupValidator = Ember.Object.create({ - check: function (model) { - var data = model.getProperties('name', 'email', 'password'), - validationErrors = []; +import NewUserValidator from 'ghost/validators/new-user'; - if (!validator.isLength(data.name, 1)) { - validationErrors.push({ - message: 'Please enter a name.' - }); - } - - if (!validator.isEmail(data.email)) { - validationErrors.push({ - message: 'Invalid Email.' - }); - } - - if (!validator.isLength(data.password, 8)) { - validationErrors.push({ - message: 'Password must be at least 8 characters long.' - }); - } - - return validationErrors; - } -}); - -export default SignupValidator; +export default NewUserValidator.create();