0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00

Merge pull request #3412 from novaugust/credentials-validation-convergance

Create new user validator to DRY up validators
This commit is contained in:
Hannah Wolfe 2014-07-27 19:38:24 +01:00
commit 8c017de4d3
3 changed files with 36 additions and 49 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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();