From 14282d7a6f711757269040241b81b9feb94b9590 Mon Sep 17 00:00:00 2001 From: Dmitry Kulak Date: Mon, 14 Feb 2022 12:42:59 +0300 Subject: [PATCH] Web: Studio: SSO: Added validation --- .../public/locales/ru/SingleSignOn.json | 6 +- .../integration/SingleSignOn/FieldMapping.js | 6 + .../integration/SingleSignOn/IdpSettings.js | 2 + .../SingleSignOn/ProviderMetadata.js | 3 + .../sub-components/SimpleFormField.js | 4 + .../sub-components/SimpleTextInput.js | 3 + web/ASC.Web.Client/src/store/SsoFormStore.js | 116 +++++++++++++++++- 7 files changed, 138 insertions(+), 2 deletions(-) diff --git a/web/ASC.Web.Client/public/locales/ru/SingleSignOn.json b/web/ASC.Web.Client/public/locales/ru/SingleSignOn.json index bddc1d761d..4e03b039ca 100644 --- a/web/ASC.Web.Client/public/locales/ru/SingleSignOn.json +++ b/web/ASC.Web.Client/public/locales/ru/SingleSignOn.json @@ -11,6 +11,7 @@ "CustomEntryTooltip": "Надпись для кнопки, которая используется для входа на портал с помощью сервиса Single Sign-on", "DecryptStatements": "Расшифровывать утверждения", "DownloadMetadataXML": "Скачать XML-файл метаданных поставщика сервиса", + "EmptyFieldErrorMessage": "Поле не заполнено", "EndpointURL": "URL-адрес конечной точки единого входа IdP:", "EndpointURLTooltip": "URL-адрес, используемый для единого входа на стороне поставщика учетных записей", "FirstName": "Имя", @@ -49,5 +50,8 @@ "TurnOnSSOCaption": "Включите эту опцию, если вы хотите автоматически добавить на портал пользователей из сервиса SSO", "TurnOnSSOTooltip": "Включите эту опцию, если вы хотите автоматически добавить на портал пользователей из сервиса SSO", "UploadXML": "Для автоматического заполнения необходимых полей загрузите метаданные из XML-файла", - "UploadXMLPlaceholder": "URL адрес XML-файла метаданных" + "UploadXMLPlaceholder": "URL адрес XML-файла метаданных", + "emailErrorMessage": "Неверный формат электронной почты", + "phoneErrorMessage": "Неверный формат номера телефона", + "urlErrorMessage": "Недопустимый URL-адрес" } \ No newline at end of file diff --git a/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/FieldMapping.js b/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/FieldMapping.js index 8af811f8f8..2ca1a3852c 100644 --- a/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/FieldMapping.js +++ b/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/FieldMapping.js @@ -29,6 +29,7 @@ const FieldMapping = ({ FormStore, t }) => { labelText={t("FirstName")} name="firstName" placeholder="givenName" + t={t} tabIndex={16} /> @@ -37,6 +38,7 @@ const FieldMapping = ({ FormStore, t }) => { labelText={t("LastName")} name="lastName" placeholder="sn" + t={t} tabIndex={17} /> @@ -45,6 +47,7 @@ const FieldMapping = ({ FormStore, t }) => { labelText={t("Common:Email")} name="email" placeholder="sn" + t={t} tabIndex={18} /> @@ -53,6 +56,7 @@ const FieldMapping = ({ FormStore, t }) => { labelText={t("Location")} name="location" placeholder="sn" + t={t} tabIndex={19} /> @@ -61,6 +65,7 @@ const FieldMapping = ({ FormStore, t }) => { labelText={t("Title")} name="title" placeholder="sn" + t={t} tabIndex={20} /> @@ -69,6 +74,7 @@ const FieldMapping = ({ FormStore, t }) => { labelText={t("Common:Phone")} name="phone" placeholder="sn" + t={t} tabIndex={21} /> diff --git a/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/IdpSettings.js b/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/IdpSettings.js index e3cf3c5489..1cdd529602 100644 --- a/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/IdpSettings.js +++ b/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/IdpSettings.js @@ -23,6 +23,7 @@ const IdpSettings = ({ FormStore, t }) => { labelText={t("CustomEntryButton")} name="spLoginLabel" placeholder="Single Sign-on" + t={t} tabIndex={4} tooltipContent={t("CustomEntryTooltip")} /> @@ -32,6 +33,7 @@ const IdpSettings = ({ FormStore, t }) => { labelText={t("ProviderURL")} name="entityId" placeholder="https://www.test.com" + t={t} tabIndex={5} tooltipContent={t("ProviderURLTooltip")} /> diff --git a/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/ProviderMetadata.js b/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/ProviderMetadata.js index 87fc912244..7039ef9456 100644 --- a/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/ProviderMetadata.js +++ b/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/ProviderMetadata.js @@ -17,6 +17,7 @@ const ProviderMetadata = ({ FormStore, t }) => { labelText={t("SPEntityId")} name="sp_entityId" placeholder="https://www.test.com" + t={t} tabIndex={25} tooltipContent={t("SPEntityIdTooltip")} /> @@ -26,6 +27,7 @@ const ProviderMetadata = ({ FormStore, t }) => { labelText={t("SPAssertionConsumerURL")} name="sp_assertionConsumerUrl" placeholder="https://www.test.com" + t={t} tabIndex={26} tooltipContent={t("SPAssertionConsumerURLTooltip")} /> @@ -35,6 +37,7 @@ const ProviderMetadata = ({ FormStore, t }) => { labelText={t("SPSingleLogoutURL")} name="sp_singleLogoutUrl" placeholder="https://www.test.com" + t={t} tabIndex={27} tooltipContent={t("SPSingleLogoutURLTooltip")} /> diff --git a/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/sub-components/SimpleFormField.js b/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/sub-components/SimpleFormField.js index 838202692e..9e1cc1eaa9 100644 --- a/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/sub-components/SimpleFormField.js +++ b/web/ASC.Web.Client/src/components/pages/Settings/categories/integration/SingleSignOn/sub-components/SimpleFormField.js @@ -11,11 +11,14 @@ const SimpleFormField = ({ labelText, name, placeholder, + t, tabIndex, tooltipContent, }) => { return ( { console.log("новый сертификат:", this.newIdpCertificate); this.isModalVisible = false; + this.newIdpCertificate = ""; + }; + + onBlur = (e) => { + const field = e.target.name; + const fieldTouched = `${field}Touched`; + const fieldError = `${field}HasError`; + const fieldErrorMessage = `${field}ErrorMessage`; + + const value = e.target.value; + + this[fieldTouched] = true; + + const validateResult = this.validate(value, this.getFieldType(field)); + + if (typeof validateResult !== "string") { + this[fieldError] = false; + this[fieldErrorMessage] = null; + } else { + this[fieldError] = true; + this[fieldErrorMessage] = validateResult; + } + }; + + getFieldType = (field) => { + if (field.toLowerCase().includes("url")) return "url"; + if (field.includes("entityId")) return "url"; + if (field.includes("email")) return "email"; + if (field.includes("phone")) return "phone"; + return "string"; + }; + + validate = (string, type) => { + string = string.trim(); + + if (string.length === 0) return "EmptyFieldErrorMessage"; + + if (type === "string") return true; + + return regExps[type].test(string) ? true : `${type}ErrorMessage`; }; }