2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-07-11 23:01:42 +04:00
|
|
|
var UserValidator = Ember.Object.create({
|
|
|
|
check: function (model) {
|
|
|
|
var validator = this.validators[model.get('status')];
|
|
|
|
|
|
|
|
if (typeof validator !== 'function') {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return validator(model);
|
|
|
|
},
|
|
|
|
|
|
|
|
validators: {
|
|
|
|
invited: function (model) {
|
|
|
|
var validationErrors = [],
|
|
|
|
email = model.get('email'),
|
2014-07-23 10:13:20 +04:00
|
|
|
roles = model.get('roles');
|
2014-07-11 23:01:42 +04:00
|
|
|
|
|
|
|
if (!validator.isEmail(email)) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Please supply a valid email address'});
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 10:13:20 +04:00
|
|
|
if (roles.length < 1) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Please select a role'});
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return validationErrors;
|
|
|
|
},
|
|
|
|
|
|
|
|
active: function (model) {
|
|
|
|
var validationErrors = [],
|
|
|
|
name = model.get('name'),
|
|
|
|
bio = model.get('bio'),
|
|
|
|
email = model.get('email'),
|
|
|
|
location = model.get('location'),
|
|
|
|
website = model.get('website');
|
|
|
|
|
|
|
|
if (!validator.isLength(name, 0, 150)) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Name is too long'});
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isLength(bio, 0, 200)) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Bio is too long'});
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isEmail(email)) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Please supply a valid email address'});
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isLength(location, 0, 150)) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Location is too long'});
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
|
|
|
|
2014-08-01 00:29:35 +04:00
|
|
|
if (!Ember.isEmpty(website) &&
|
2014-11-17 07:35:32 +03:00
|
|
|
(!validator.isURL(website, {require_protocol: false}) ||
|
2014-07-14 20:32:55 +04:00
|
|
|
!validator.isLength(website, 0, 2000))) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Website is not a valid url'});
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
2014-07-14 20:32:55 +04:00
|
|
|
|
|
|
|
return validationErrors;
|
2014-07-11 23:01:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default UserValidator;
|