Check if old password is empty

This commit is contained in:
Šimon Brandner 2020-11-22 09:26:51 +01:00
parent cd197133aa
commit dbce418b63

View file

@ -28,6 +28,7 @@ import Modal from "../../../Modal";
import PassphraseField from "../auth/PassphraseField"; import PassphraseField from "../auth/PassphraseField";
import CountlyAnalytics from "../../../CountlyAnalytics"; import CountlyAnalytics from "../../../CountlyAnalytics";
const FIELD_OLD_PASSWORD = 'field_old_password';
const FIELD_NEW_PASSWORD = 'field_new_password'; const FIELD_NEW_PASSWORD = 'field_new_password';
const FIELD_NEW_PASSWORD_CONFIRM = 'field_new_password_confirm'; const FIELD_NEW_PASSWORD_CONFIRM = 'field_new_password_confirm';
@ -191,6 +192,22 @@ export default class ChangePassword extends React.Component {
}); });
}; };
onOldPasswordValidate = async fieldState => {
const result = await this.validateOldPasswordRules(fieldState);
this.markFieldValid(FIELD_OLD_PASSWORD, result.valid);
return result;
};
validateOldPasswordRules = withValidation({
rules: [
{
key: "required",
test: ({ value, allowEmpty }) => allowEmpty || !!value,
invalid: () => _t("Passwords can't be empty"),
}
],
});
onChangeNewPassword = (ev) => { onChangeNewPassword = (ev) => {
this.setState({ this.setState({
newPassword: ev.target.value, newPassword: ev.target.value,
@ -261,8 +278,9 @@ export default class ChangePassword extends React.Component {
} }
const fieldIDsInDisplayOrder = [ const fieldIDsInDisplayOrder = [
FIELD_OLD_PASSWORD,
FIELD_NEW_PASSWORD, FIELD_NEW_PASSWORD,
FIELD_NEW_PASSWORD_CONFIRM FIELD_NEW_PASSWORD_CONFIRM,
]; ];
// Run all fields with stricter validation that no longer allows empty // Run all fields with stricter validation that no longer allows empty
@ -329,10 +347,13 @@ export default class ChangePassword extends React.Component {
<form className={this.props.className} onSubmit={this.onClickChange}> <form className={this.props.className} onSubmit={this.onClickChange}>
<div className={rowClassName}> <div className={rowClassName}>
<Field <Field
ref={field => this[FIELD_OLD_PASSWORD] = field}
type="password" type="password"
label={_t('Current password')} label={_t('Current password')}
value={this.state.oldPassword} value={this.state.oldPassword}
onChange={this.onChangeOldPassword} onChange={this.onChangeOldPassword}
onValidate={this.onOldPasswordValidate}
onBlur={() => CountlyAnalytics.instance.track("onboarding_registration_email_blur")}
/> />
</div> </div>
<div className={rowClassName}> <div className={rowClassName}>