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) {
|
2022-10-07 22:13:42 +03:00
|
|
|
let name = model.name;
|
2014-07-25 23:17:16 +04:00
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (!validator.isLength(name || '', 1)) {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add('name', 'Please enter a name.');
|
|
|
|
model.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) {
|
2022-10-07 22:13:42 +03:00
|
|
|
let email = model.email;
|
2014-07-25 23:17:16 +04:00
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (isBlank(email)) {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add('email', 'Please enter an email.');
|
2015-07-07 20:34:23 +03:00
|
|
|
this.invalidate();
|
|
|
|
} else if (!validator.isEmail(email)) {
|
2022-10-07 22:13:42 +03:00
|
|
|
model.errors.add('email', 'Invalid Email.');
|
2015-06-07 06:19:19 +03:00
|
|
|
this.invalidate();
|
2014-07-25 23:17:16 +04:00
|
|
|
}
|
2018-09-17 18:03:58 +03:00
|
|
|
|
2022-10-07 22:13:42 +03:00
|
|
|
model.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
|
|
|
}
|
|
|
|
});
|