HM-129. HM-130. Исправлены ошибки при смене пароля в Личном кабинете
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import Component from '../../../../core/components/component/Component';
|
import Component from '../../../../core/components/component/Component';
|
||||||
import FormControl from '../../../../core/components/form-control/FormControl';
|
import FormControl from '../../../../core/components/form-control/FormControl';
|
||||||
import {FORM_TYPES, EVENTS} from '../../../../core/consts';
|
import {FORM_TYPES, EVENTS} from '../../../../core/consts';
|
||||||
import {INPUT_IDS, LABELS} from './consts';
|
import {INPUT_IDS, LABELS, ERRORS} from './consts';
|
||||||
import notify from '../../../../services/NotifyService';
|
import notify from '../../../../services/NotifyService';
|
||||||
import profileServiceApi from '../../../../api/ProfileServiceAPI';
|
import profileServiceApi from '../../../../api/ProfileServiceAPI';
|
||||||
|
|
||||||
@ -48,22 +48,22 @@ class ProfileContent extends Component {
|
|||||||
const newPasswordRepeat = this.newPasswordRepeat.getValue();
|
const newPasswordRepeat = this.newPasswordRepeat.getValue();
|
||||||
|
|
||||||
if (!oldPassword) {
|
if (!oldPassword) {
|
||||||
this.oldPassword.setError('Заполните старый пароль');
|
this.oldPassword.setError(ERRORS.TYPED_OLD_PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!newPassword) {
|
if (!newPassword) {
|
||||||
this.newPassword.setError('Заполните новый пароль');
|
this.newPassword.setError(ERRORS.TYPED_NEW_PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isEqualPassword = newPassword === newPasswordRepeat;
|
const isEqualPassword = newPassword === newPasswordRepeat;
|
||||||
|
|
||||||
if (!isEqualPassword) {
|
if (!isEqualPassword) {
|
||||||
this.newPassword.setError('Пароли не совпадают');
|
this.newPassword.setError(ERRORS.PASSWORD_NOT_EQUAL);
|
||||||
this.newPasswordRepeat.setError('Пароли не совпадают');
|
this.newPasswordRepeat.setError(ERRORS.PASSWORD_NOT_EQUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!newPasswordRepeat) {
|
if (!newPasswordRepeat) {
|
||||||
this.newPasswordRepeat.setError('Повторите новый пароль');
|
this.newPasswordRepeat.setError(ERRORS.REPEAT_PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.form.checkValidity() && isEqualPassword;
|
return this.form.checkValidity() && isEqualPassword;
|
||||||
@ -81,9 +81,16 @@ class ProfileContent extends Component {
|
|||||||
if (this.validateInputs()) {
|
if (this.validateInputs()) {
|
||||||
const oldPassword = this.oldPassword.getValue();
|
const oldPassword = this.oldPassword.getValue();
|
||||||
const newPassword = this.newPassword.getValue();
|
const newPassword = this.newPassword.getValue();
|
||||||
await profileServiceApi.changePassword(oldPassword, newPassword);
|
try {
|
||||||
|
await profileServiceApi.changePassword(oldPassword, newPassword);
|
||||||
|
} catch (e) {
|
||||||
|
if (e?.response?.data?.message === ERRORS.NOT_CORRECT_PASSWORD) {
|
||||||
|
this.oldPassword.setError(ERRORS.NOT_CORRECT_PASSWORD);
|
||||||
|
}
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
this.clearForm();
|
this.clearForm();
|
||||||
notify.success('Пароль успешно изменен');
|
notify.success(LABELS.SUCCESS_CHANGE_PASSWORD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,4 +11,13 @@ export const LABELS = {
|
|||||||
OLD_PASSWORD_PLACEHOLDER: 'Введите старый пароль',
|
OLD_PASSWORD_PLACEHOLDER: 'Введите старый пароль',
|
||||||
NEW_PASSWORD_PLACEHOLDER: 'Введите новый пароль',
|
NEW_PASSWORD_PLACEHOLDER: 'Введите новый пароль',
|
||||||
NEW_PASSWORD_REPEAT_PLACEHOLDER: 'Введите новый пароль еще раз',
|
NEW_PASSWORD_REPEAT_PLACEHOLDER: 'Введите новый пароль еще раз',
|
||||||
|
SUCCESS_CHANGE_PASSWORD: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ERRORS = {
|
||||||
|
TYPED_OLD_PASSWORD: 'Заполните старый пароль',
|
||||||
|
TYPED_NEW_PASSWORD: 'Заполните новый пароль',
|
||||||
|
PASSWORD_NOT_EQUAL: 'Пароли не совпадают',
|
||||||
|
REPEAT_PASSWORD: 'Повторите новый пароль',
|
||||||
|
NOT_CORRECT_PASSWORD: 'Не верный старый пароль',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user