From 10c07e09f3d880e84c041214ca31be09b7d7ebc3 Mon Sep 17 00:00:00 2001 From: Vitalii Lysak Date: Tue, 6 Sep 2022 14:47:21 +0300 Subject: SILABMC-295: add error handle for password change --- src/locales/ru-RU.json | 17 ++++++++++++ .../SecurityAndAccess/UserManagementStore.js | 32 ++++++++++++++++------ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/locales/ru-RU.json b/src/locales/ru-RU.json index 85b780ec..e7dd4fda 100644 --- a/src/locales/ru-RU.json +++ b/src/locales/ru-RU.json @@ -93,6 +93,23 @@ "lastDay": "Последние сутки" } }, + "passwordErrors": { + "it is based on your username": "Пароль на основе имени пользователя", + "it is based upon your password entry": "Пароль на основе введенного вами пароля", + "it is derived from your password entry": "Пароль получен из введенного вами пароля", + "it is derivable from your password entry": "Пароль получается из введенного вами пароля", + "it's derivable from your password entry": "Пароль получается из введенного вами пароля", + "you are not registered in the password file": "Пароль не зарегистрирован в файле паролей", + "it is WAY too short": "Пароль СЛИШКОМ короткий", + "it is too short": "Пароль слишком короткий", + "it does not contain enough DIFFERENT characters": "Пароль не содержит достаточного числа РАЗЛИЧНЫХ символов", + "it is all whitespace": "Пароль состоит из пробелов", + "it is too simplistic/systematic": "Пароль слишком простой", + "it looks like a National Insurance number.": "Пароль похож на номер государственного страхования.", + "it is based on a dictionary word": "Пароль на основе слова из словаря", + "it is based on a (reversed) dictionary word": "Пароль на основе (перевернутого) слова из словаря", + "error loading dictionary": "Ошибка при загрузке словаря" + }, "chart": { "thresholdFailure": "Пороговое значение отказ", "thresholdWarning": "Пороговое значение предупреждения", diff --git a/src/store/modules/SecurityAndAccess/UserManagementStore.js b/src/store/modules/SecurityAndAccess/UserManagementStore.js index 362f3f64..d373e6e4 100644 --- a/src/store/modules/SecurityAndAccess/UserManagementStore.js +++ b/src/store/modules/SecurityAndAccess/UserManagementStore.js @@ -114,10 +114,17 @@ const UserManagementStore = { ) .catch((error) => { console.log(error); - const message = i18n.t('pageUserManagement.toast.errorCreateUser', { - username, - }); - throw new Error(message); + if (error.response) { + const codeRaw = + error.response.data['Password@Message.ExtendedInfo'][0].Oem + .OpenBMC.ErrorMessage[0]; + const code = codeRaw.replace('BAD PASSWORD: ', ''); + const title = i18n.t('pageUserManagement.toast.errorCreateUser', { + username, + }); + const message = i18n.t(`passwordErrors.${code}`); + throw new Error(title + '\n' + message); + } }); }, async updateUser( @@ -139,11 +146,18 @@ const UserManagementStore = { }) ) .catch((error) => { - console.log(error); - const message = i18n.t('pageUserManagement.toast.errorUpdateUser', { - username: originalUsername, - }); - throw new Error(message); + if (error.response) { + console.log(error); + const codeRaw = + error.response.data['Password@Message.ExtendedInfo'][0].Oem + .OpenBMC.ErrorMessage[0]; + const code = codeRaw.replace('BAD PASSWORD: ', ''); + const title = i18n.t('pageUserManagement.toast.errorUpdateUser', { + username: originalUsername, + }); + const message = i18n.t(`passwordErrors.${code}`); + throw new Error(title + '\n' + message); + } }); }, async deleteUser({ dispatch }, username) { -- cgit v1.2.3