mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
786e0ac9c5
no issue - if a plain native class instance with tracked properties is validated against the `ValidationEngine` and it's associated validators would cause errors by assuming that the instance has a `.get()` method - updated all model access in `ValidationEngine` and the validators to use direct property access which works for both native class and `EmberObject` instances
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
import BaseValidator from './base';
|
|
import PasswordValidatorMixin from './mixins/password';
|
|
import validator from 'validator';
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
export default BaseValidator.extend(PasswordValidatorMixin, {
|
|
init() {
|
|
this.properties = this.properties || ['name', 'email', 'password'];
|
|
this._super(...arguments);
|
|
},
|
|
|
|
name(model) {
|
|
let name = model.name;
|
|
|
|
if (!validator.isLength(name || '', 1)) {
|
|
model.errors.add('name', 'Please enter a name.');
|
|
model.hasValidated.addObject('email');
|
|
this.invalidate();
|
|
}
|
|
},
|
|
|
|
email(model) {
|
|
let email = model.email;
|
|
|
|
if (isBlank(email)) {
|
|
model.errors.add('email', 'Please enter an email.');
|
|
this.invalidate();
|
|
} else if (!validator.isEmail(email)) {
|
|
model.errors.add('email', 'Invalid Email.');
|
|
this.invalidate();
|
|
}
|
|
|
|
model.hasValidated.addObject('email');
|
|
},
|
|
|
|
password(model) {
|
|
this.passwordValidation(model);
|
|
}
|
|
});
|