2017-10-26 12:02:17 +02:00
|
|
|
import PasswordValidator from 'ghost-admin/validators/password';
|
2018-03-19 18:56:09 +01:00
|
|
|
import validator from 'npm:validator';
|
|
|
|
import {isBlank} from '@ember/utils';
|
2014-07-25 21:17:16 +02:00
|
|
|
|
2017-10-26 12:02:17 +02:00
|
|
|
export default PasswordValidator.extend({
|
2017-11-24 19:53:19 +01:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.properties = this.properties || ['name', 'email', 'password'];
|
|
|
|
},
|
2015-06-07 05:19:19 +02:00
|
|
|
|
2015-10-28 12:36:45 +01:00
|
|
|
name(model) {
|
|
|
|
let name = model.get('name');
|
2014-07-25 21:17:16 +02:00
|
|
|
|
2018-03-19 18:56:09 +01:00
|
|
|
if (!validator.isLength(name || '', 1)) {
|
2015-06-07 05:19:19 +02:00
|
|
|
model.get('errors').add('name', 'Please enter a name.');
|
|
|
|
this.invalidate();
|
2014-07-25 21:17:16 +02:00
|
|
|
}
|
2015-06-07 05:19:19 +02:00
|
|
|
},
|
2015-10-28 12:36:45 +01:00
|
|
|
|
|
|
|
email(model) {
|
|
|
|
let email = model.get('email');
|
2014-07-25 21:17:16 +02:00
|
|
|
|
2018-03-19 18:56:09 +01:00
|
|
|
if (isBlank(email)) {
|
2015-07-07 19:34:23 +02:00
|
|
|
model.get('errors').add('email', 'Please enter an email.');
|
|
|
|
this.invalidate();
|
|
|
|
} else if (!validator.isEmail(email)) {
|
2015-06-07 05:19:19 +02:00
|
|
|
model.get('errors').add('email', 'Invalid Email.');
|
|
|
|
this.invalidate();
|
2014-07-25 21:17:16 +02:00
|
|
|
}
|
2015-06-07 05:19:19 +02:00
|
|
|
},
|
2015-10-28 12:36:45 +01:00
|
|
|
|
|
|
|
password(model) {
|
2017-10-26 12:02:17 +02:00
|
|
|
this.passwordValidation(model);
|
2014-07-25 21:17:16 +02:00
|
|
|
}
|
|
|
|
});
|