2018-09-17 17:52:07 +03:00
|
|
|
import BaseValidator from './base';
|
|
|
|
import PasswordValidatorMixin from './mixins/password';
|
2019-01-22 16:09:38 +03:00
|
|
|
import validator from 'validator';
|
2018-03-19 20:56:09 +03:00
|
|
|
import {isBlank} from '@ember/utils';
|
2014-07-25 23:17:16 +04:00
|
|
|
|
2018-09-17 17:52:07 +03:00
|
|
|
export default BaseValidator.extend(PasswordValidatorMixin, {
|
2017-11-24 21:53:19 +03:00
|
|
|
init() {
|
|
|
|
this.properties = this.properties || ['name', 'email', 'password'];
|
2018-09-17 17:52:07 +03:00
|
|
|
this._super(...arguments);
|
2017-11-24 21:53:19 +03:00
|
|
|
},
|
2015-06-07 06:19:19 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
name(model) {
|
|
|
|
let name = model.get('name');
|
2014-07-25 23:17:16 +04:00
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (!validator.isLength(name || '', 1)) {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('name', 'Please enter a name.');
|
2018-09-17 18:03:58 +03:00
|
|
|
model.get('hasValidated').addObject('email');
|
2015-06-07 06:19:19 +03:00
|
|
|
this.invalidate();
|
2014-07-25 23:17:16 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
email(model) {
|
|
|
|
let email = model.get('email');
|
2014-07-25 23:17:16 +04:00
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (isBlank(email)) {
|
2015-07-07 20:34:23 +03:00
|
|
|
model.get('errors').add('email', 'Please enter an email.');
|
|
|
|
this.invalidate();
|
|
|
|
} else if (!validator.isEmail(email)) {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('email', 'Invalid Email.');
|
|
|
|
this.invalidate();
|
2014-07-25 23:17:16 +04:00
|
|
|
}
|
2018-09-17 18:03:58 +03:00
|
|
|
|
|
|
|
model.get('hasValidated').addObject('email');
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
password(model) {
|
2017-10-26 13:02:17 +03:00
|
|
|
this.passwordValidation(model);
|
2014-07-25 23:17:16 +04:00
|
|
|
}
|
|
|
|
});
|