2018-09-17 17:52:07 +03:00
|
|
|
import BaseValidator from './base';
|
|
|
|
import PasswordValidatorMixin from './mixins/password';
|
2018-03-19 20:56:09 +03:00
|
|
|
import validator from 'npm:validator';
|
|
|
|
import {isBlank} from '@ember/utils';
|
2015-08-19 14:55:40 +03:00
|
|
|
|
2018-09-17 17:52:07 +03:00
|
|
|
const resetValidator = BaseValidator.extend(PasswordValidatorMixin, {
|
|
|
|
init() {
|
|
|
|
this.properties = this.properties || ['newPassword'];
|
|
|
|
this._super(...arguments);
|
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
newPassword(model) {
|
|
|
|
let p1 = model.get('newPassword');
|
|
|
|
let p2 = model.get('ne2Password');
|
2014-06-27 23:08:16 +04:00
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (isBlank(p1)) {
|
2015-07-07 20:14:23 +03:00
|
|
|
model.get('errors').add('newPassword', 'Please enter a password.');
|
|
|
|
this.invalidate();
|
2018-03-19 20:56:09 +03:00
|
|
|
} else if (!validator.equals(p1, p2 || '')) {
|
2015-07-11 20:04:19 +03:00
|
|
|
model.get('errors').add('ne2Password', 'The two new passwords don\'t match.');
|
|
|
|
this.invalidate();
|
2014-06-27 23:08:16 +04:00
|
|
|
}
|
2017-10-26 13:02:17 +03:00
|
|
|
|
|
|
|
this.passwordValidation(model, p1, 'newPassword');
|
2014-06-27 23:08:16 +04:00
|
|
|
}
|
|
|
|
});
|
2018-09-17 17:52:07 +03:00
|
|
|
|
|
|
|
export default resetValidator.create();
|