mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Create new user validator to DRY up validators
No issue - Created NewUserValidator class to DRY up validation of a models name, email, and password - Changed SignUpValidator to be an instance of NewUserValidator - Changed SetUpValidator to extend NewUserValidator
This commit is contained in:
parent
d2d25faa5c
commit
0d7033f662
3 changed files with 36 additions and 49 deletions
28
core/client/validators/new-user.js
Normal file
28
core/client/validators/new-user.js
Normal 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;
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue