mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
ee36284440
no issue - PasswordValidator was only adding a function to the base class but it introduced a confusing inheritance hierarchy that's easier to reason about when it's a mixin instead - swapped the `this.properties =` and `this._super()` calls in the `init` function of `new-user` so that the default can actually be applied - previously the BaseValidator `init` method was doing `this.properties = []` which meant the default fallback in extended classes wouldn't work
29 lines
905 B
JavaScript
29 lines
905 B
JavaScript
import BaseValidator from './base';
|
|
import PasswordValidatorMixin from './mixins/password';
|
|
import validator from 'npm:validator';
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
const resetValidator = BaseValidator.extend(PasswordValidatorMixin, {
|
|
init() {
|
|
this.properties = this.properties || ['newPassword'];
|
|
this._super(...arguments);
|
|
},
|
|
|
|
newPassword(model) {
|
|
let p1 = model.get('newPassword');
|
|
let p2 = model.get('ne2Password');
|
|
|
|
if (isBlank(p1)) {
|
|
model.get('errors').add('newPassword', 'Please enter a password.');
|
|
this.invalidate();
|
|
} else if (!validator.equals(p1, p2 || '')) {
|
|
model.get('errors').add('ne2Password', 'The two new passwords don\'t match.');
|
|
this.invalidate();
|
|
}
|
|
|
|
this.passwordValidation(model, p1, 'newPassword');
|
|
}
|
|
});
|
|
|
|
export default resetValidator.create();
|