From fcd43134020a94ea4a8d88bc1a0b5066fa6a971e Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 13:05:49 +0300 Subject: [PATCH 01/22] Web: Common : Login : Fixed white screen on ios --- web/ASC.Web.Common/src/pages/login/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/src/pages/login/index.js b/web/ASC.Web.Common/src/pages/login/index.js index 095fad6a1f..73fb18125b 100644 --- a/web/ASC.Web.Common/src/pages/login/index.js +++ b/web/ASC.Web.Common/src/pages/login/index.js @@ -470,7 +470,7 @@ const LoginForm = (props) => { <> {isLoaded && ( - + From f8cb5ab12c052deb5d67151083e3ce8da7264ec8 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 13:06:19 +0300 Subject: [PATCH 02/22] web: common: bump version --- web/ASC.Web.Common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/package.json b/web/ASC.Web.Common/package.json index 3bd684977d..6f604c3e28 100644 --- a/web/ASC.Web.Common/package.json +++ b/web/ASC.Web.Common/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-common", - "version": "1.0.280", + "version": "1.0.281", "description": "Ascensio System SIA common components and solutions library", "license": "AGPL-3.0", "files": [ From 96b5b2658b83294389771aa74679753efd7812bf Mon Sep 17 00:00:00 2001 From: gopienkonikita Date: Mon, 30 Nov 2020 13:20:58 +0300 Subject: [PATCH 03/22] Web: Common: fixed text alignment on login page --- web/ASC.Web.Common/src/pages/login/index.js | 44 +++++++-------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/web/ASC.Web.Common/src/pages/login/index.js b/web/ASC.Web.Common/src/pages/login/index.js index 73fb18125b..ef59186dca 100644 --- a/web/ASC.Web.Common/src/pages/login/index.js +++ b/web/ASC.Web.Common/src/pages/login/index.js @@ -76,8 +76,7 @@ const LoginContainer = styled.div` padding: 14px 0; .login-checkbox-wrapper { - position: absolute; - display: inline-flex; + display: flex; .login-checkbox { float: left; @@ -85,23 +84,11 @@ const LoginContainer = styled.div` font-size: 12px; } } - - .login-tooltip { - display: inline-flex; - - @media (min-width: 1025px) { - margin-left: 8px; - margin-top: 4px; - } - @media (max-width: 1024px) { - padding: 4px 8px 8px 8px; - } - } } .login-link { - float: right; - line-height: 16px; + line-height: 18px; + margin-left: auto; } } @@ -365,25 +352,24 @@ class Form extends Component { onChange={this.onChangeCheckbox} label={{t("Remember")}} /> - {t("RememberHelper")} } - /> + />*/} + + {t("ForgotPassword")} + - - - {t("ForgotPassword")} - {openDialog && ( From f8fc428bd042dfd44e03b45a9923e9c6d254ba54 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 13:46:52 +0300 Subject: [PATCH 04/22] Web: Common : Login : Fixed white screen on ios --- .../src/components/PageLayout/sub-components/section.js | 1 + web/ASC.Web.Common/src/pages/login/index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/src/components/PageLayout/sub-components/section.js b/web/ASC.Web.Common/src/components/PageLayout/sub-components/section.js index b82f619123..8ecd7e48dd 100644 --- a/web/ASC.Web.Common/src/components/PageLayout/sub-components/section.js +++ b/web/ASC.Web.Common/src/components/PageLayout/sub-components/section.js @@ -19,6 +19,7 @@ const StyledSection = styled.section` flex-grow: 1; display: flex; flex-direction: column; + flex: 1 1 0%; // IOS fix, issue with flex-direction: column and empty height /*width: ${(props) => `${props.widthProp}px`};*/ .layout-progress-bar { bottom: 0; diff --git a/web/ASC.Web.Common/src/pages/login/index.js b/web/ASC.Web.Common/src/pages/login/index.js index ef59186dca..f18df80438 100644 --- a/web/ASC.Web.Common/src/pages/login/index.js +++ b/web/ASC.Web.Common/src/pages/login/index.js @@ -456,7 +456,7 @@ const LoginForm = (props) => { <> {isLoaded && ( - + From 2f8a82727f01e5c8e841aaca351f88ace6d35239 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 13:47:16 +0300 Subject: [PATCH 05/22] web: common: bump version --- web/ASC.Web.Common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/package.json b/web/ASC.Web.Common/package.json index 6f604c3e28..c911e39cc2 100644 --- a/web/ASC.Web.Common/package.json +++ b/web/ASC.Web.Common/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-common", - "version": "1.0.281", + "version": "1.0.282", "description": "Ascensio System SIA common components and solutions library", "license": "AGPL-3.0", "files": [ From 30b5c5781f6c95d46cddb83d2b4430c2cd411159 Mon Sep 17 00:00:00 2001 From: gopienkonikita Date: Mon, 30 Nov 2020 15:02:15 +0300 Subject: [PATCH 06/22] Web: Components: fixed avatar background color --- web/ASC.Web.Components/src/components/avatar/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Components/src/components/avatar/index.js b/web/ASC.Web.Components/src/components/avatar/index.js index 02609a5174..6994ba83d2 100644 --- a/web/ASC.Web.Components/src/components/avatar/index.js +++ b/web/ASC.Web.Components/src/components/avatar/index.js @@ -5,7 +5,7 @@ import { Icons } from "../icons"; import Link from "../link"; const whiteColor = "#FFFFFF"; -const avatarBackground = "#ECEEF1"; +const avatarBackground = "#D0D5DA"; const namedAvatarBackground = "#2DA7DB"; const noneUserSelect = css` From 22d81111911a8034b8beb59679c852b67ae2dff3 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 15:02:09 +0300 Subject: [PATCH 07/22] Web: Common : Login : Fixed display login error --- web/ASC.Web.Common/src/pages/login/index.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/web/ASC.Web.Common/src/pages/login/index.js b/web/ASC.Web.Common/src/pages/login/index.js index f18df80438..07f6cd4228 100644 --- a/web/ASC.Web.Common/src/pages/login/index.js +++ b/web/ASC.Web.Common/src/pages/login/index.js @@ -198,6 +198,7 @@ class Form extends Component { onSubmit = () => { const { errorText, identifier, password } = this.state; + // eslint-disable-next-line no-unused-vars, react/prop-types const { login, setIsLoaded, history, hashSettings, homepage } = this.props; errorText && this.setState({ errorText: "" }); @@ -229,7 +230,12 @@ class Form extends Component { } }) .catch((error) => { - this.setState({ errorText: error, isLoading: false }); + this.setState({ + errorText: error, + identifierValid: !error, + passwordValid: !error, + isLoading: false, + }); }); }; @@ -237,8 +243,8 @@ class Form extends Component { const { match, t, - hashSettings, - reloadPortalSettings, + hashSettings, // eslint-disable-line react/prop-types + reloadPortalSettings, // eslint-disable-line react/prop-types organizationName, } = this.props; const { error, confirmedEmail } = match.params; @@ -302,7 +308,7 @@ class Form extends Component { isVertical={true} labelVisible={false} hasError={!identifierValid} - errorMessage={t("RequiredFieldMessage")} + errorMessage={errorText ? errorText : t("RequiredFieldMessage")} //TODO: Add wrong login server error > )} + {/* TODO: old error indication + {errorText} - + */} {socialButtons.length ? ( From 292dc42d5288a03f0dc83935e28e85df656a6a98 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 15:02:56 +0300 Subject: [PATCH 08/22] Web: Components : Input, Textarea : Fixed placeholder color --- .../src/components/text-input/index.js | 20 +++++++++++-------- .../src/components/textarea/index.js | 14 +++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/web/ASC.Web.Components/src/components/text-input/index.js b/web/ASC.Web.Components/src/components/text-input/index.js index 7a5fdcac7e..f835d3e035 100755 --- a/web/ASC.Web.Components/src/components/text-input/index.js +++ b/web/ASC.Web.Components/src/components/text-input/index.js @@ -5,8 +5,7 @@ import commonInputStyle from "../text-input/common-input-styles"; import MaskedInput from "react-text-mask"; import isEqual from "lodash/isEqual"; -/* eslint-disable no-unused-vars */ -/* eslint-disable react/prop-types */ +/* eslint-disable no-unused-vars, react/prop-types */ const Input = ({ isAutoFocussed, isDisabled, @@ -25,8 +24,7 @@ const Input = ({ ) : ( ); -/* eslint-enable react/prop-types */ -/* eslint-enable no-unused-vars */ +/* eslint-enable react/prop-types, no-unused-vars */ const StyledInput = styled(Input).attrs((props) => ({ id: props.id, @@ -77,25 +75,31 @@ const StyledInput = styled(Input).attrs((props) => ({ transition: all 0.2s ease 0s; ::-webkit-input-placeholder { - color: ${(props) => (props.isDisabled ? "#A3A9AE" : "#D0D5DA")}; + color: "#A3A9AE"; font-family: "Open Sans", sans-serif; user-select: none; } :-moz-placeholder { - color: ${(props) => (props.isDisabled ? "#A3A9AE" : "#D0D5DA")}; + color: "#A3A9AE"; font-family: "Open Sans", sans-serif; user-select: none; } ::-moz-placeholder { - color: ${(props) => (props.isDisabled ? "#A3A9AE" : "#D0D5DA")}; + color: "#A3A9AE"; font-family: "Open Sans", sans-serif; user-select: none; } :-ms-input-placeholder { - color: ${(props) => (props.isDisabled ? "#A3A9AE" : "#D0D5DA")}; + color: "#A3A9AE"; + font-family: "Open Sans", sans-serif; + user-select: none; + } + + ::placeholder { + color: "#A3A9AE"; font-family: "Open Sans", sans-serif; user-select: none; } diff --git a/web/ASC.Web.Components/src/components/textarea/index.js b/web/ASC.Web.Components/src/components/textarea/index.js index a796243b9c..9e8dba87a5 100644 --- a/web/ASC.Web.Components/src/components/textarea/index.js +++ b/web/ASC.Web.Components/src/components/textarea/index.js @@ -56,25 +56,31 @@ const StyledTextarea = styled(ClearTextareaAutosize)` } ::-webkit-input-placeholder { - color: ${(props) => (props.isDisabled ? "#D0D5DA" : "#D0D5DA")}; + color: "#A3A9AE"; font-family: "Open Sans", sans-serif; user-select: none; } :-moz-placeholder { - color: ${(props) => (props.isDisabled ? "#D0D5DA" : "#D0D5DA")}; + color: "#A3A9AE"; font-family: "Open Sans", sans-serif; user-select: none; } ::-moz-placeholder { - color: ${(props) => (props.isDisabled ? "#D0D5DA" : "#D0D5DA")}; + color: "#A3A9AE"; font-family: "Open Sans", sans-serif; user-select: none; } :-ms-input-placeholder { - color: ${(props) => (props.isDisabled ? "#D0D5DA" : "#D0D5DA")}; + color: "#A3A9AE"; + font-family: "Open Sans", sans-serif; + user-select: none; + } + + ::placeholder { + color: "#A3A9AE"; font-family: "Open Sans", sans-serif; user-select: none; } From 3c0381c03fb96b7ce96e6bebd383972021ef4346 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 15:03:08 +0300 Subject: [PATCH 09/22] web: components: bump version --- web/ASC.Web.Components/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Components/package.json b/web/ASC.Web.Components/package.json index a1ebf06c9b..f274f3d949 100644 --- a/web/ASC.Web.Components/package.json +++ b/web/ASC.Web.Components/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-components", - "version": "1.0.488", + "version": "1.0.489", "description": "Ascensio System SIA component library", "license": "AGPL-3.0", "main": "dist/asc-web-components.js", From a7ac0572015325862a1e91e2cbfc4d5ee783eafc Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 15:03:21 +0300 Subject: [PATCH 10/22] web: common: bump version --- web/ASC.Web.Common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/package.json b/web/ASC.Web.Common/package.json index c911e39cc2..9b027a8c07 100644 --- a/web/ASC.Web.Common/package.json +++ b/web/ASC.Web.Common/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-common", - "version": "1.0.282", + "version": "1.0.283", "description": "Ascensio System SIA common components and solutions library", "license": "AGPL-3.0", "files": [ From 4b20b62223fc79b2ec2b7a9ccbf2772c8921cdd4 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 15:59:27 +0300 Subject: [PATCH 11/22] Web: Common : PageLayout : Fixed css --- .../src/components/PageLayout/sub-components/section.js | 1 - 1 file changed, 1 deletion(-) diff --git a/web/ASC.Web.Common/src/components/PageLayout/sub-components/section.js b/web/ASC.Web.Common/src/components/PageLayout/sub-components/section.js index 8ecd7e48dd..b82f619123 100644 --- a/web/ASC.Web.Common/src/components/PageLayout/sub-components/section.js +++ b/web/ASC.Web.Common/src/components/PageLayout/sub-components/section.js @@ -19,7 +19,6 @@ const StyledSection = styled.section` flex-grow: 1; display: flex; flex-direction: column; - flex: 1 1 0%; // IOS fix, issue with flex-direction: column and empty height /*width: ${(props) => `${props.widthProp}px`};*/ .layout-progress-bar { bottom: 0; From ebe385e5a342a29e81a243776d0dff845a2b7f27 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 30 Nov 2020 15:59:42 +0300 Subject: [PATCH 12/22] web: common: bump version --- web/ASC.Web.Common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/package.json b/web/ASC.Web.Common/package.json index 9b027a8c07..7c6ccf0014 100644 --- a/web/ASC.Web.Common/package.json +++ b/web/ASC.Web.Common/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-common", - "version": "1.0.283", + "version": "1.0.284", "description": "Ascensio System SIA common components and solutions library", "license": "AGPL-3.0", "files": [ From 7c136b576ed3e51d86073710f5d5b923a11b0192 Mon Sep 17 00:00:00 2001 From: gopienkonikita Date: Mon, 30 Nov 2020 16:40:42 +0300 Subject: [PATCH 13/22] Web: Common: fixed register text align --- .../src/pages/login/sub-components/register-container.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/ASC.Web.Common/src/pages/login/sub-components/register-container.js b/web/ASC.Web.Common/src/pages/login/sub-components/register-container.js index 2fe8f81908..5a8bba3749 100644 --- a/web/ASC.Web.Common/src/pages/login/sub-components/register-container.js +++ b/web/ASC.Web.Common/src/pages/login/sub-components/register-container.js @@ -10,6 +10,9 @@ import { connect } from "react-redux"; import i18n from "../i18n"; const StyledRegister = styled(Box)` + display: flex; + align-items: center; + justify-content: center; z-index: 184; width: 100%; height: 66px; @@ -60,9 +63,7 @@ const Register = ({ t }) => { return ( <> - - {t("Register")} - + {t("Register")} {visible && ( From eb2ae72026c21caee3ce8160a3f9f7c153c85545 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Tue, 1 Dec 2020 17:19:07 +0300 Subject: [PATCH 14/22] Web: Files : Components: Hide logs --- .../ASC.Files/Client/src/components/Article/Body/index.js | 2 +- .../Client/src/components/pages/Home/Section/Body/index.js | 2 +- .../Client/src/components/pages/Home/Section/Filter/index.js | 2 +- products/ASC.Files/Client/src/components/pages/Home/index.js | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/products/ASC.Files/Client/src/components/Article/Body/index.js b/products/ASC.Files/Client/src/components/Article/Body/index.js index 7160b833b9..ce0add7bdb 100644 --- a/products/ASC.Files/Client/src/components/Article/Body/index.js +++ b/products/ASC.Files/Client/src/components/Article/Body/index.js @@ -107,7 +107,7 @@ class ArticleBodyContent extends React.Component { const { showNewFilesPanel, expandedKeys, newFolderId } = this.state; //console.log("Article Body render", this.props, this.state.expandedKeys); - console.log("Article Body render"); + //console.log("Article Body render"); return ( <> {showNewFilesPanel && ( diff --git a/products/ASC.Files/Client/src/components/pages/Home/Section/Body/index.js b/products/ASC.Files/Client/src/components/pages/Home/Section/Body/index.js index 0b7789c39c..4cb4a739ef 100644 --- a/products/ASC.Files/Client/src/components/pages/Home/Section/Body/index.js +++ b/products/ASC.Files/Client/src/components/pages/Home/Section/Body/index.js @@ -1496,7 +1496,7 @@ class SectionBodyContent extends React.Component { }; render() { - console.log("Files Home SectionBodyContent render", this.props); + //console.log("Files Home SectionBodyContent render", this.props); const { viewer, diff --git a/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js index 7f7ceee278..c8a1a4db98 100644 --- a/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js @@ -295,7 +295,7 @@ class SectionFilterContent extends React.Component { } render() { - console.log("Filter render"); + //console.log("Filter render"); const selectedFilterData = this.getSelectedFilterData(); const { t, language, firstLoad, sectionWidth } = this.props; const filterColumnCount = diff --git a/products/ASC.Files/Client/src/components/pages/Home/index.js b/products/ASC.Files/Client/src/components/pages/Home/index.js index 5acf8ef10e..fa94393f41 100644 --- a/products/ASC.Files/Client/src/components/pages/Home/index.js +++ b/products/ASC.Files/Client/src/components/pages/Home/index.js @@ -128,7 +128,7 @@ class PureHome extends React.Component { if (filter) { const folderId = filter.folder; - console.log("filter", filter); + //console.log("filter", filter); return fetchFiles(folderId, filter); } @@ -165,7 +165,7 @@ class PureHome extends React.Component { } render() { - console.log("Home render"); + //console.log("Home render"); const { progressData, viewAs, From d03584fcdd153a29287e44d430f92bf839ae0048 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Fri, 4 Dec 2020 11:38:15 +0300 Subject: [PATCH 15/22] Web: Fixed isAuthenticated logic --- products/ASC.Files/Client/src/App.js | 14 ++++---- products/ASC.Files/Client/src/index.js | 5 +-- products/ASC.People/Client/src/App.js | 14 ++++---- products/ASC.People/Client/src/index.js | 5 +-- web/ASC.Web.Client/src/App.js | 19 ++++++---- .../src/helpers/confirmRoute.js | 9 +++-- web/ASC.Web.Client/src/index.js | 5 +-- web/ASC.Web.Common/src/api/client.js | 14 ++------ web/ASC.Web.Common/src/api/user/index.js | 17 +++++++-- .../src/components/NavMenu/index.js | 2 +- .../components/PrivateRoute/PrivateRoute.js | 20 +++++++---- .../src/components/PublicRoute/PublicRoute.js | 8 ++--- web/ASC.Web.Common/src/constants/index.js | 1 - web/ASC.Web.Common/src/pages/login/index.js | 29 +++++++++++---- web/ASC.Web.Common/src/store/auth/actions.js | 35 ++++++++++++++++--- web/ASC.Web.Common/src/store/auth/reducer.js | 9 +++-- .../src/store/auth/selectors.js | 2 ++ web/ASC.Web.Common/src/utils/index.js | 16 +-------- 18 files changed, 132 insertions(+), 92 deletions(-) diff --git a/products/ASC.Files/Client/src/App.js b/products/ASC.Files/Client/src/App.js index aaa9bf0178..9610fa28e0 100644 --- a/products/ASC.Files/Client/src/App.js +++ b/products/ASC.Files/Client/src/App.js @@ -10,7 +10,6 @@ import config from "../package.json"; import { store as commonStore, - constants, history, PrivateRoute, PublicRoute, @@ -32,8 +31,8 @@ const { setCurrentProductId, setCurrentProductHomePage, getPortalCultures, + getIsAuthenticated, } = commonStore.auth.actions; -const { AUTH_KEY } = constants; class App extends React.Component { constructor(props) { @@ -53,13 +52,14 @@ class App extends React.Component { getPortalCultures, fetchTreeFolders, setIsLoaded, + getIsAuthenticated, + isAuthenticated, } = this.props; setModuleInfo(); + getIsAuthenticated(); - const token = localStorage.getItem(AUTH_KEY); - - if (!token) { + if (!isAuthenticated) { return setIsLoaded(); } @@ -131,15 +131,17 @@ class App extends React.Component { } const mapStateToProps = (state) => { - const { settings } = state.auth; + const { settings, isAuthenticated } = state.auth; const { homepage } = settings; return { + isAuthenticated, homepage: homepage || config.homepage, }; }; const mapDispatchToProps = (dispatch) => { return { + getIsAuthenticated: () => getIsAuthenticated(dispatch), setModuleInfo: () => { dispatch(setCurrentProductHomePage(config.homepage)); dispatch(setCurrentProductId("e67be73d-f9ae-4ce1-8fec-1880cb518cb4")); diff --git a/products/ASC.Files/Client/src/index.js b/products/ASC.Files/Client/src/index.js index 9159dc9220..d907011b7e 100644 --- a/products/ASC.Files/Client/src/index.js +++ b/products/ASC.Files/Client/src/index.js @@ -9,10 +9,7 @@ import "./custom.scss"; import App from "./App"; import * as serviceWorker from "./serviceWorker"; -import { ErrorBoundary, utils } from "asc-web-common"; -const { redirectToDefaultPage } = utils; - -redirectToDefaultPage(); +import { ErrorBoundary } from "asc-web-common"; ReactDOM.render( diff --git a/products/ASC.People/Client/src/App.js b/products/ASC.People/Client/src/App.js index 8a38a036db..41e56d1602 100644 --- a/products/ASC.People/Client/src/App.js +++ b/products/ASC.People/Client/src/App.js @@ -16,7 +16,6 @@ import { Offline, utils, store as commonStore, - constants, NavMenu, Main, toastr, @@ -34,8 +33,8 @@ const { setCurrentProductHomePage, getPortalPasswordSettings, getPortalCultures, + getIsAuthenticated, } = commonStore.auth.actions; -const { AUTH_KEY } = constants; /*const Profile = lazy(() => import("./components/pages/Profile")); const ProfileAction = lazy(() => import("./components/pages/ProfileAction")); @@ -55,13 +54,14 @@ class App extends React.Component { fetchGroups, fetchPeople, setIsLoaded, + isAuthenticated, + getIsAuthenticated, } = this.props; setModuleInfo(); + getIsAuthenticated(); - const token = localStorage.getItem(AUTH_KEY); - - if (!token) { + if (!isAuthenticated) { return setIsLoaded(); } @@ -147,15 +147,17 @@ class App extends React.Component { } const mapStateToProps = (state) => { - const { settings } = state.auth; + const { settings, isAuthenticated } = state.auth; const { homepage } = settings; return { + isAuthenticated, homepage: homepage || config.homepage, }; }; const mapDispatchToProps = (dispatch) => { return { + getIsAuthenticated: () => getIsAuthenticated(dispatch), setModuleInfo: () => { dispatch(setCurrentProductHomePage(config.homepage)); dispatch(setCurrentProductId("f4d98afd-d336-4332-8778-3c6945c81ea0")); diff --git a/products/ASC.People/Client/src/index.js b/products/ASC.People/Client/src/index.js index 31e84c5053..d40a4ed77d 100644 --- a/products/ASC.People/Client/src/index.js +++ b/products/ASC.People/Client/src/index.js @@ -7,10 +7,7 @@ import "./custom.scss"; import App from "./App"; import * as serviceWorker from "./serviceWorker"; -import { ErrorBoundary, utils } from "asc-web-common"; -const { redirectToDefaultPage } = utils; - -redirectToDefaultPage(); +import { ErrorBoundary } from "asc-web-common"; ReactDOM.render( diff --git a/web/ASC.Web.Client/src/App.js b/web/ASC.Web.Client/src/App.js index ad22eb07b4..3cc917c89a 100644 --- a/web/ASC.Web.Client/src/App.js +++ b/web/ASC.Web.Client/src/App.js @@ -28,21 +28,26 @@ const { getUser, getPortalSettings, getModules, + getIsAuthenticated, } = CommonStore.auth.actions; class App extends React.Component { componentDidMount() { utils.removeTempContent(); - const { getPortalSettings, getUser, getModules, setIsLoaded } = this.props; + const { + getPortalSettings, + getUser, + getModules, + setIsLoaded, + getIsAuthenticated, + } = this.props; - const { AUTH_KEY } = constants; - - const token = localStorage.getItem(AUTH_KEY); + getIsAuthenticated(); const requests = []; - if (!token) { + if (!getIsAuthenticated) { requests.push(getPortalSettings()); } else if (!window.location.pathname.includes("confirm/EmailActivation")) { requests.push(getUser()); @@ -102,9 +107,10 @@ class App extends React.Component { } const mapStateToProps = (state) => { - const { modules, isLoaded, settings } = state.auth; + const { modules, isLoaded, settings, isAuthenticated } = state.auth; const { organizationName } = settings; return { + isAuthenticated, modules, isLoaded, organizationName, @@ -113,6 +119,7 @@ const mapStateToProps = (state) => { const mapDispatchToProps = (dispatch) => { return { + getIsAuthenticated: () => getIsAuthenticated(dispatch), getPortalSettings: () => getPortalSettings(dispatch), getUser: () => getUser(dispatch), getModules: () => getModules(dispatch), diff --git a/web/ASC.Web.Client/src/helpers/confirmRoute.js b/web/ASC.Web.Client/src/helpers/confirmRoute.js index 1c011518cc..24667f8196 100644 --- a/web/ASC.Web.Client/src/helpers/confirmRoute.js +++ b/web/ASC.Web.Client/src/helpers/confirmRoute.js @@ -4,9 +4,8 @@ import { ValidationResult } from "./../helpers/constants"; import { Loader } from "asc-web-components"; import { connect } from "react-redux"; import { withRouter } from "react-router"; -import { api, constants, utils, PageLayout } from "asc-web-common"; +import { api, utils, PageLayout } from "asc-web-common"; const { checkConfirmLink } = api.user; -const { AUTH_KEY } = constants; const { getObjectByLocation } = utils; class ConfirmRoute extends React.Component { @@ -19,14 +18,14 @@ class ConfirmRoute extends React.Component { } componentDidMount() { - const { forUnauthorized, history } = this.props; + const { forUnauthorized, history, isAuthenticated } = this.props; - if (forUnauthorized && localStorage.getItem(AUTH_KEY)) + if (forUnauthorized && isAuthenticated) return history.push( `/error=Access error. You should be unauthorized for performing this action` ); - const { location, isAuthenticated } = this.props; + const { location } = this.props; const { search } = location; const queryParams = getObjectByLocation(location); diff --git a/web/ASC.Web.Client/src/index.js b/web/ASC.Web.Client/src/index.js index 83983e21e2..0b23aec805 100644 --- a/web/ASC.Web.Client/src/index.js +++ b/web/ASC.Web.Client/src/index.js @@ -5,10 +5,7 @@ import store from "./store/store"; import "./custom.scss"; import App from "./App"; import * as serviceWorker from "./serviceWorker"; -import { ErrorBoundary, utils } from "asc-web-common"; -const { redirectToDefaultPage } = utils; - -redirectToDefaultPage(); +import { ErrorBoundary } from "asc-web-common"; ReactDOM.render( diff --git a/web/ASC.Web.Common/src/api/client.js b/web/ASC.Web.Common/src/api/client.js index 41d07bded7..64e1641982 100644 --- a/web/ASC.Web.Common/src/api/client.js +++ b/web/ASC.Web.Common/src/api/client.js @@ -1,5 +1,4 @@ import axios from "axios"; -import { AUTH_KEY } from "../constants"; //import history from "../history"; const PREFIX = "api"; @@ -16,8 +15,6 @@ const client = axios.create({ timeout: 30000, // default is `0` (no timeout) }); -setAuthorizationToken(localStorage.getItem(AUTH_KEY)); - client.interceptors.response.use( (response) => { return response; @@ -25,7 +22,7 @@ client.interceptors.response.use( (error) => { switch (true) { case error.response.status === 401: - setAuthorizationToken(); + setWithCredentialsStatus(false); window.location.href = "/login"; break; case error.response.status === 402: @@ -41,13 +38,8 @@ client.interceptors.response.use( } ); -export function setAuthorizationToken(token) { - client.defaults.withCredentials = true; - if (token) { - localStorage.setItem(AUTH_KEY, true); - } else { - localStorage.clear(); - } +export function setWithCredentialsStatus(state) { + client.defaults.withCredentials = state; } export function setClientBasePath(path) { diff --git a/web/ASC.Web.Common/src/api/user/index.js b/web/ASC.Web.Common/src/api/user/index.js index 4a22efb2cc..cbdfb2d982 100644 --- a/web/ASC.Web.Common/src/api/user/index.js +++ b/web/ASC.Web.Common/src/api/user/index.js @@ -1,4 +1,4 @@ -import { request, setAuthorizationToken } from "../client"; +import { request, setWithCredentialsStatus } from "../client"; export function login(userName, passwordHash) { const data = { @@ -11,7 +11,7 @@ export function login(userName, passwordHash) { url: "/authentication.json", data, }).then((tokenData) => { - setAuthorizationToken(true); + setWithCredentialsStatus(true); return Promise.resolve(tokenData); }); } @@ -21,7 +21,7 @@ export function logout() { method: "post", url: "/authentication/logout", }).then(() => { - setAuthorizationToken(); + setWithCredentialsStatus(false); return Promise.resolve(); }); } @@ -33,3 +33,14 @@ export function checkConfirmLink(data) { data, }); } + +export function checkIsAuthenticated() { + return request({ + method: "get", + url: "/authentication", + withCredentials: true, + }).then((state) => { + setWithCredentialsStatus(state); + return Promise.resolve(); + }); +} diff --git a/web/ASC.Web.Common/src/components/NavMenu/index.js b/web/ASC.Web.Common/src/components/NavMenu/index.js index 10f73f4b99..db00f04f68 100644 --- a/web/ASC.Web.Common/src/components/NavMenu/index.js +++ b/web/ASC.Web.Common/src/components/NavMenu/index.js @@ -104,7 +104,7 @@ class NavMenu extends React.Component { const isAsideAvailable = !!asideContent; - console.log("NavMenu render", this.state, this.props); + //console.log("NavMenu render", this.state, this.props); return ( diff --git a/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js b/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js index 76262c4c24..894acdbfba 100644 --- a/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js +++ b/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js @@ -5,7 +5,7 @@ import { connect } from "react-redux"; //import { Loader } from "asc-web-components"; //import PageLayout from "../PageLayout"; import { getCurrentUser, isAdmin, isMe } from "../../store/auth/selectors.js"; -import { AUTH_KEY } from "../../constants"; +import { getIsAuthenticated } from "../../store/auth/actions.js"; import { Error401, Error404 } from "../../pages/errors"; import isEmpty from "lodash/isEmpty"; @@ -17,9 +17,12 @@ const PrivateRoute = ({ component: Component, ...rest }) => { allowForMe, user, computedMatch, + getIsAuthenticated, } = rest; const { userId } = computedMatch.params; + //getIsAuthenticated(); + const renderComponent = (props) => { if (!isAuthenticated) { console.log("PrivateRoute render Redirect to login", rest); @@ -76,15 +79,18 @@ const PrivateRoute = ({ component: Component, ...rest }) => { }; function mapStateToProps(state) { - const { isLoaded, isAuthenticated } = state.auth; + const { isAuthenticated } = state.auth; return { isAdmin: isAdmin(state), user: getCurrentUser(state), - isAuthenticated: !( - !localStorage.getItem(AUTH_KEY) || - (isLoaded && !isAuthenticated) - ), + isAuthenticated: isAuthenticated, }; } -export default connect(mapStateToProps)(PrivateRoute); +const mapDispatchToProps = (dispatch) => { + return { + getIsAuthenticated: () => getIsAuthenticated(dispatch), + }; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(PrivateRoute); diff --git a/web/ASC.Web.Common/src/components/PublicRoute/PublicRoute.js b/web/ASC.Web.Common/src/components/PublicRoute/PublicRoute.js index fbc798722b..8e8146d0c6 100644 --- a/web/ASC.Web.Common/src/components/PublicRoute/PublicRoute.js +++ b/web/ASC.Web.Common/src/components/PublicRoute/PublicRoute.js @@ -1,16 +1,13 @@ /* eslint-disable react/prop-types */ import React from "react"; import { Redirect, Route } from "react-router-dom"; -import { AUTH_KEY } from "../../constants"; import { connect } from "react-redux"; export const PublicRoute = ({ component: Component, ...rest }) => { - const token = localStorage.getItem(AUTH_KEY); - - const { wizardToken, wizardCompleted } = rest; + const { wizardToken, wizardCompleted, isAuthenticated } = rest; const renderComponent = (props) => { - if (token) { + if (isAuthenticated) { return ( { function mapStateToProps(state) { return { + isAuthenticated: state.auth.isAuthenticated, wizardToken: state.auth.settings.wizardToken, wizardCompleted: state.auth.settings.wizardCompleted, }; diff --git a/web/ASC.Web.Common/src/constants/index.js b/web/ASC.Web.Common/src/constants/index.js index 1cecf9ff64..24376323de 100644 --- a/web/ASC.Web.Common/src/constants/index.js +++ b/web/ASC.Web.Common/src/constants/index.js @@ -1,4 +1,3 @@ -export const AUTH_KEY = "asc_auth_key"; export const LANGUAGE = "language"; export const ARTICLE_PINNED_KEY = "asc_article_pinned_key"; diff --git a/web/ASC.Web.Common/src/pages/login/index.js b/web/ASC.Web.Common/src/pages/login/index.js index 24bc94a606..f895080553 100644 --- a/web/ASC.Web.Common/src/pages/login/index.js +++ b/web/ASC.Web.Common/src/pages/login/index.js @@ -24,11 +24,12 @@ import { login, setIsLoaded, reloadPortalSettings, + getIsAuthenticated, + redirectToDefaultPage, } from "../../store/auth/actions"; import { sendInstructionsToChangePassword } from "../../api/people"; import Register from "./sub-components/register-container"; import { createPasswordHash } from "../../utils"; -import { redirectToDefaultPage } from "../../utils"; const { getLanguage } = store.auth.selectors; const LoginContainer = styled.div` display: flex; @@ -113,7 +114,8 @@ const LoginContainer = styled.div` const LoginFormWrapper = styled.div` display: grid; - grid-template-rows: ${props => props.enabledJoin ? css`1fr 66px` : css`1fr`}; + grid-template-rows: ${(props) => + props.enabledJoin ? css`1fr 66px` : css`1fr`}; width: 100%; height: calc(100vh-56px); `; @@ -198,7 +200,12 @@ class Form extends Component { onSubmit = () => { const { errorText, identifier, password } = this.state; - const { login, setIsLoaded, hashSettings } = this.props; + const { + login, + setIsLoaded, + hashSettings, + redirectToDefaultPage, + } = this.props; errorText && this.setState({ errorText: "" }); let hasError = false; @@ -464,7 +471,7 @@ const LoginForm = (props) => { - + @@ -479,16 +486,22 @@ LoginForm.propTypes = { }; function mapStateToProps(state) { - const { isLoaded, settings } = state.auth; - const { greetingSettings, organizationName, hashSettings, enabledJoin } = settings; + const { isLoaded, settings, isAuthenticated } = state.auth; + const { + greetingSettings, + organizationName, + hashSettings, + enabledJoin, + } = settings; return { + isAuthenticated, isLoaded, organizationName, language: getLanguage(state), greetingTitle: greetingSettings, hashSettings, - enabledJoin + enabledJoin, }; } @@ -496,4 +509,6 @@ export default connect(mapStateToProps, { login, setIsLoaded, reloadPortalSettings, + getIsAuthenticated, + redirectToDefaultPage, })(withRouter(LoginForm)); diff --git a/web/ASC.Web.Common/src/store/auth/actions.js b/web/ASC.Web.Common/src/store/auth/actions.js index 6a63cb4511..be692508ec 100644 --- a/web/ASC.Web.Common/src/store/auth/actions.js +++ b/web/ASC.Web.Common/src/store/auth/actions.js @@ -1,4 +1,5 @@ import { default as api } from "../../api"; +import { setWithCredentialsStatus } from "../../api/client"; export const LOGIN_POST = "LOGIN_POST"; export const SET_CURRENT_USER = "SET_CURRENT_USER"; @@ -17,6 +18,7 @@ export const SET_CURRENT_PRODUCT_HOME_PAGE = "SET_CURRENT_PRODUCT_HOME_PAGE"; export const SET_GREETING_SETTINGS = "SET_GREETING_SETTINGS"; export const SET_CUSTOM_NAMES = "SET_CUSTOM_NAMES"; export const SET_WIZARD_COMPLETED = "SET_WIZARD_COMPLETED"; +export const SET_IS_AUTHENTICATED = "SET_IS_AUTHENTICATED"; export function setCurrentUser(user) { return { @@ -128,13 +130,27 @@ export function setWizardComplete() { }; } +export function setIsAuthenticated(isAuthenticated) { + return { + type: SET_IS_AUTHENTICATED, + isAuthenticated, + }; +} + export function getUser(dispatch) { return api.people .getUser() .then((user) => dispatch(setCurrentUser(user))) + .then(() => dispatch(setIsAuthenticated(true))) .catch((err) => dispatch(setCurrentUser({}))); } +export function getIsAuthenticated(dispatch) { + return api.user + .checkIsAuthenticated() + .then((res) => dispatch(setIsAuthenticated(res))); +} + export function getPortalSettings(dispatch) { return api.settings.getSettings().then((settings) => { const { passwordHash: hashSettings, ...otherSettings } = settings; @@ -176,16 +192,20 @@ export function login(user, hash) { return api.user .login(user, hash) .then(() => dispatch(setIsLoaded(false))) + .then(() => { + setWithCredentialsStatus(true); + return dispatch(setIsAuthenticated(true)); + }) .then(() => getUserInfo(dispatch)); }; } export function logout() { return (dispatch) => { - return api.user - .logout() - .then(() => dispatch(setLogout())) - .then(() => dispatch(setIsLoaded(true))); + return api.user.logout().then(() => { + setWithCredentialsStatus(false); + return dispatch(setLogout()); + }); }; } @@ -210,3 +230,10 @@ export function getPortalPasswordSettings(dispatch, confirmKey = null) { export const reloadPortalSettings = () => { return (dispatch) => getPortalSettings(dispatch); }; + +export function redirectToDefaultPage() { + return (_, getState) => { + const defaultPage = getState().settings.defaultPage; + setTimeout(() => window.location.replace(defaultPage), 0); + }; +} diff --git a/web/ASC.Web.Common/src/store/auth/reducer.js b/web/ASC.Web.Common/src/store/auth/reducer.js index 667996db7c..8ea36d29cb 100644 --- a/web/ASC.Web.Common/src/store/auth/reducer.js +++ b/web/ASC.Web.Common/src/store/auth/reducer.js @@ -15,9 +15,10 @@ import { SET_GREETING_SETTINGS, SET_CUSTOM_NAMES, SET_WIZARD_COMPLETED, + SET_IS_AUTHENTICATED, } from "./actions"; import isEmpty from "lodash/isEmpty"; -import { LANGUAGE, AUTH_KEY } from "../../constants"; +import { LANGUAGE } from "../../constants"; const initialState = { isAuthenticated: false, @@ -73,10 +74,12 @@ const authReducer = (state = initialState, action) => { localStorage.getItem(LANGUAGE) !== action.user.cultureName && localStorage.setItem(LANGUAGE, action.user.cultureName); return Object.assign({}, state, { - isAuthenticated: - !isEmpty(action.user) || localStorage.getItem(AUTH_KEY), user: action.user, }); + case SET_IS_AUTHENTICATED: + return Object.assign({}, state, { + isAuthenticated: action.isAuthenticated, + }); case SET_MODULES: return Object.assign({}, state, { modules: action.modules, diff --git a/web/ASC.Web.Common/src/store/auth/selectors.js b/web/ASC.Web.Common/src/store/auth/selectors.js index 413578d640..bd4577cdde 100644 --- a/web/ASC.Web.Common/src/store/auth/selectors.js +++ b/web/ASC.Web.Common/src/store/auth/selectors.js @@ -45,6 +45,8 @@ const getCustomModules = (isAdmin) => { export const getCurrentUser = (state) => state.auth.user; +export const isAuthenticated = (state) => state.auth.isAuthenticated; + export const getCurrentUserId = (state) => state.auth.user; export const getModules = (state) => state.auth.modules; diff --git a/web/ASC.Web.Common/src/utils/index.js b/web/ASC.Web.Common/src/utils/index.js index 5e287d558f..000cf467b6 100644 --- a/web/ASC.Web.Common/src/utils/index.js +++ b/web/ASC.Web.Common/src/utils/index.js @@ -1,4 +1,4 @@ -import { AUTH_KEY, LANGUAGE } from "../constants"; +import { LANGUAGE } from "../constants"; import sjcl from "sjcl"; import { isMobile } from "react-device-detect"; @@ -44,20 +44,6 @@ export function changeLanguage( : i18n.changeLanguage("en"); } -export function redirectToDefaultPage() { - if ( - (window.location.pathname === "/" || - window.location.pathname === "" || - window.location.pathname === "/login") && - localStorage.getItem(AUTH_KEY) !== null - ) { - setTimeout(() => window.location.replace("/products/files"), 0); - return true; - } - - return false; -} - export function createPasswordHash(password, hashSettings) { if ( !password || From c32fc83399f1fb16e67555b483ca794bd1b6c7c9 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Fri, 4 Dec 2020 11:58:15 +0300 Subject: [PATCH 16/22] Web: Client: Fixed property name, added missing property --- web/ASC.Web.Client/src/App.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/ASC.Web.Client/src/App.js b/web/ASC.Web.Client/src/App.js index 3cc917c89a..747da1011e 100644 --- a/web/ASC.Web.Client/src/App.js +++ b/web/ASC.Web.Client/src/App.js @@ -41,13 +41,14 @@ class App extends React.Component { getModules, setIsLoaded, getIsAuthenticated, + isAuthenticated, } = this.props; getIsAuthenticated(); const requests = []; - if (!getIsAuthenticated) { + if (!isAuthenticated) { requests.push(getPortalSettings()); } else if (!window.location.pathname.includes("confirm/EmailActivation")) { requests.push(getUser()); From 0784453daf66aeaf3fa443f58f12a21d6dd75b94 Mon Sep 17 00:00:00 2001 From: AlexeySafronov Date: Fri, 4 Dec 2020 14:21:51 +0300 Subject: [PATCH 17/22] Fix errors on login and logout --- products/ASC.Files/Client/src/App.js | 7 ++- products/ASC.People/Client/src/App.js | 7 ++- web/ASC.Web.Client/src/App.js | 53 ++++++++++--------- web/ASC.Web.Common/src/api/user/index.js | 8 +-- .../src/components/PageLayout/index.js | 24 ++++++--- .../PageLayout/sub-components/section-body.js | 5 ++ .../components/PrivateRoute/PrivateRoute.js | 42 ++++++++------- web/ASC.Web.Common/src/pages/login/index.js | 20 ++++--- web/ASC.Web.Common/src/store/auth/actions.js | 19 ++++--- web/ASC.Web.Common/src/store/auth/reducer.js | 2 +- web/ASC.Web.Common/src/utils/index.js | 10 ++++ 11 files changed, 109 insertions(+), 88 deletions(-) diff --git a/products/ASC.Files/Client/src/App.js b/products/ASC.Files/Client/src/App.js index 9610fa28e0..735b4dfc19 100644 --- a/products/ASC.Files/Client/src/App.js +++ b/products/ASC.Files/Client/src/App.js @@ -53,11 +53,10 @@ class App extends React.Component { fetchTreeFolders, setIsLoaded, getIsAuthenticated, - isAuthenticated, } = this.props; setModuleInfo(); - getIsAuthenticated(); + getIsAuthenticated().then((isAuthenticated) => { if (!isAuthenticated) { return setIsLoaded(); @@ -80,6 +79,7 @@ class App extends React.Component { .finally(() => { setIsLoaded(); }); + }); } render() { @@ -131,10 +131,9 @@ class App extends React.Component { } const mapStateToProps = (state) => { - const { settings, isAuthenticated } = state.auth; + const { settings } = state.auth; const { homepage } = settings; return { - isAuthenticated, homepage: homepage || config.homepage, }; }; diff --git a/products/ASC.People/Client/src/App.js b/products/ASC.People/Client/src/App.js index 41e56d1602..3b49cca27b 100644 --- a/products/ASC.People/Client/src/App.js +++ b/products/ASC.People/Client/src/App.js @@ -54,12 +54,11 @@ class App extends React.Component { fetchGroups, fetchPeople, setIsLoaded, - isAuthenticated, getIsAuthenticated, } = this.props; setModuleInfo(); - getIsAuthenticated(); + getIsAuthenticated().then((isAuthenticated) => { if (!isAuthenticated) { return setIsLoaded(); @@ -82,6 +81,7 @@ class App extends React.Component { .finally(() => { setIsLoaded(); }); + }); } render() { @@ -147,10 +147,9 @@ class App extends React.Component { } const mapStateToProps = (state) => { - const { settings, isAuthenticated } = state.auth; + const { settings } = state.auth; const { homepage } = settings; return { - isAuthenticated, homepage: homepage || config.homepage, }; }; diff --git a/web/ASC.Web.Client/src/App.js b/web/ASC.Web.Client/src/App.js index 747da1011e..8ffca09b01 100644 --- a/web/ASC.Web.Client/src/App.js +++ b/web/ASC.Web.Client/src/App.js @@ -3,7 +3,6 @@ import { Router, Route, Switch } from "react-router-dom"; import { connect } from "react-redux"; import { store as CommonStore, - constants, history, PrivateRoute, PublicRoute, @@ -28,7 +27,7 @@ const { getUser, getPortalSettings, getModules, - getIsAuthenticated, + getIsAuthenticated } = CommonStore.auth.actions; class App extends React.Component { @@ -41,28 +40,34 @@ class App extends React.Component { getModules, setIsLoaded, getIsAuthenticated, - isAuthenticated, + //defaultPage } = this.props; - getIsAuthenticated(); + getIsAuthenticated() + .then((isAuthenticated) => { + const requests = []; + if (!isAuthenticated) { + requests.push(getPortalSettings()); + } else if (!window.location.pathname.includes("confirm/EmailActivation")) { - const requests = []; + // debugger; + // if(utils.tryRedirectTo(defaultPage)) //TODO: Re-write redirect to defaultPage after get settings + // return; - if (!isAuthenticated) { - requests.push(getPortalSettings()); - } else if (!window.location.pathname.includes("confirm/EmailActivation")) { - requests.push(getUser()); - requests.push(getPortalSettings()); - requests.push(getModules()); - } - - Promise.all(requests) - .catch((e) => { - toastr.error(e); - }) - .finally(() => { - setIsLoaded(); - }); + requests.push(getUser()); + requests.push(getPortalSettings()); + requests.push(getModules()); + } + + Promise.all(requests) + .catch((e) => { + toastr.error(e); + }) + .finally(() => { + setIsLoaded(); + }); + }) + .catch((err) => toastr.error(err)); } render() { @@ -108,13 +113,13 @@ class App extends React.Component { } const mapStateToProps = (state) => { - const { modules, isLoaded, settings, isAuthenticated } = state.auth; - const { organizationName } = settings; + const { modules, isLoaded, settings } = state.auth; + const { organizationName, defaultPage } = settings; return { - isAuthenticated, modules, isLoaded, organizationName, + defaultPage }; }; @@ -124,7 +129,7 @@ const mapDispatchToProps = (dispatch) => { getPortalSettings: () => getPortalSettings(dispatch), getUser: () => getUser(dispatch), getModules: () => getModules(dispatch), - setIsLoaded: () => dispatch(setIsLoaded(true)), + setIsLoaded: () => dispatch(setIsLoaded(true)) }; }; diff --git a/web/ASC.Web.Common/src/api/user/index.js b/web/ASC.Web.Common/src/api/user/index.js index cbdfb2d982..eecac7f9b9 100644 --- a/web/ASC.Web.Common/src/api/user/index.js +++ b/web/ASC.Web.Common/src/api/user/index.js @@ -10,9 +10,6 @@ export function login(userName, passwordHash) { method: "post", url: "/authentication.json", data, - }).then((tokenData) => { - setWithCredentialsStatus(true); - return Promise.resolve(tokenData); }); } @@ -20,9 +17,6 @@ export function logout() { return request({ method: "post", url: "/authentication/logout", - }).then(() => { - setWithCredentialsStatus(false); - return Promise.resolve(); }); } @@ -41,6 +35,6 @@ export function checkIsAuthenticated() { withCredentials: true, }).then((state) => { setWithCredentialsStatus(state); - return Promise.resolve(); + return state; }); } diff --git a/web/ASC.Web.Common/src/components/PageLayout/index.js b/web/ASC.Web.Common/src/components/PageLayout/index.js index 6f2fd740f9..c7514aff30 100644 --- a/web/ASC.Web.Common/src/components/PageLayout/index.js +++ b/web/ASC.Web.Common/src/components/PageLayout/index.js @@ -81,6 +81,9 @@ class PageLayoutComponent extends React.Component { isArticleVisible: isArticleVisibleAndPinned, isArticlePinned: isArticleVisibleAndPinned, }; + + this.timeoutHandler = null; + this.intervalHandler = null; } componentDidUpdate(prevProps) { @@ -103,6 +106,11 @@ class PageLayoutComponent extends React.Component { "orientationchange", this.orientationChangeHandler ); + + if(this.intervalHandler) + clearInterval(this.intervalHandler); + if(this.timeoutHandler) + clearTimeout(this.timeoutHandler); } orientationChangeHandler = () => { @@ -123,20 +131,22 @@ class PageLayoutComponent extends React.Component { const intervalTime = 100; const endTimeoutTime = 1000; - let interval, timeout, lastInnerHeight, noChangeCount; + let lastInnerHeight, noChangeCount; const updateHeight = () => { - clearInterval(interval); - clearTimeout(timeout); + if(this.intervalHandler) + clearInterval(this.intervalHandler); + if(this.timeoutHandler) + clearTimeout(this.timeoutHandler); - interval = null; - timeout = null; + this.intervalHandler = null; + this.timeoutHandler = null; const vh = (window.innerHeight - 57) * 0.01; document.documentElement.style.setProperty("--vh", `${vh}px`); }; - interval = setInterval(() => { + this.intervalHandler = setInterval(() => { if (window.innerHeight === lastInnerHeight) { noChangeCount++; @@ -149,7 +159,7 @@ class PageLayoutComponent extends React.Component { } }); - timeout = setTimeout(() => { + this.timeoutHandler = setTimeout(() => { updateHeight(); }, endTimeoutTime); }; diff --git a/web/ASC.Web.Common/src/components/PageLayout/sub-components/section-body.js b/web/ASC.Web.Common/src/components/PageLayout/sub-components/section-body.js index 09eaae472f..56bd2eaeb0 100644 --- a/web/ASC.Web.Common/src/components/PageLayout/sub-components/section-body.js +++ b/web/ASC.Web.Common/src/components/PageLayout/sub-components/section-body.js @@ -81,6 +81,11 @@ class SectionBody extends React.Component { this.focusRef.current.focus(); } + componentWillUnmount() { + this.focusRef = null; + this.scrollRef = null; + } + render() { //console.log("PageLayout SectionBody render"); const { diff --git a/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js b/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js index 894acdbfba..559e81f265 100644 --- a/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js +++ b/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js @@ -3,28 +3,26 @@ import React from "react"; import { Redirect, Route } from "react-router-dom"; import { connect } from "react-redux"; //import { Loader } from "asc-web-components"; -//import PageLayout from "../PageLayout"; -import { getCurrentUser, isAdmin, isMe } from "../../store/auth/selectors.js"; -import { getIsAuthenticated } from "../../store/auth/actions.js"; +import PageLayout from "../PageLayout"; +import { getCurrentUser, getIsLoaded, isAdmin, isAuthenticated, isMe } from "../../store/auth/selectors.js"; import { Error401, Error404 } from "../../pages/errors"; -import isEmpty from "lodash/isEmpty"; +import RectangleLoader from "../Loaders/RectangleLoader/RectangleLoader"; +//import isEmpty from "lodash/isEmpty"; const PrivateRoute = ({ component: Component, ...rest }) => { const { isAdmin, isAuthenticated, + isLoaded, restricted, allowForMe, user, computedMatch, - getIsAuthenticated, } = rest; const { userId } = computedMatch.params; - //getIsAuthenticated(); - const renderComponent = (props) => { - if (!isAuthenticated) { + if (isLoaded && !isAuthenticated) { console.log("PrivateRoute render Redirect to login", rest); return ( { ); } - const userLoaded = !isEmpty(user); - if (!userLoaded) { - return ; + if(!isLoaded) { + return ( + + + + + + ); } + // const userLoaded = !isEmpty(user); + // if (!userLoaded) { + // return ; + // } + // if (!userLoaded) { // console.log("PrivateRoute render Loader", rest); // return ( @@ -79,18 +87,12 @@ const PrivateRoute = ({ component: Component, ...rest }) => { }; function mapStateToProps(state) { - const { isAuthenticated } = state.auth; return { isAdmin: isAdmin(state), user: getCurrentUser(state), - isAuthenticated: isAuthenticated, + isAuthenticated: isAuthenticated(state), + isLoaded: getIsLoaded(state) }; } -const mapDispatchToProps = (dispatch) => { - return { - getIsAuthenticated: () => getIsAuthenticated(dispatch), - }; -}; - -export default connect(mapStateToProps, mapDispatchToProps)(PrivateRoute); +export default connect(mapStateToProps)(PrivateRoute); diff --git a/web/ASC.Web.Common/src/pages/login/index.js b/web/ASC.Web.Common/src/pages/login/index.js index f895080553..3a119fd1a1 100644 --- a/web/ASC.Web.Common/src/pages/login/index.js +++ b/web/ASC.Web.Common/src/pages/login/index.js @@ -10,9 +10,8 @@ import { Link, toastr, Checkbox, - HelpButton, PasswordInput, - FieldContainer, + FieldContainer } from "asc-web-components"; import PageLayout from "../../components/PageLayout"; import { connect } from "react-redux"; @@ -23,13 +22,11 @@ import ForgotPasswordModalDialog from "./sub-components/forgot-password-modal-di import { login, setIsLoaded, - reloadPortalSettings, - getIsAuthenticated, - redirectToDefaultPage, + reloadPortalSettings } from "../../store/auth/actions"; import { sendInstructionsToChangePassword } from "../../api/people"; import Register from "./sub-components/register-container"; -import { createPasswordHash } from "../../utils"; +import { createPasswordHash, tryRedirectTo } from "../../utils"; const { getLanguage } = store.auth.selectors; const LoginContainer = styled.div` display: flex; @@ -204,7 +201,7 @@ class Form extends Component { login, setIsLoaded, hashSettings, - redirectToDefaultPage, + defaultPage } = this.props; errorText && this.setState({ errorText: "" }); @@ -231,7 +228,7 @@ class Form extends Component { login(userName, hash) .then(() => { - if (!redirectToDefaultPage()) { + if (!tryRedirectTo(defaultPage)) { setIsLoaded(true); } }) @@ -450,6 +447,7 @@ Form.propTypes = { socialButtons: PropTypes.array, organizationName: PropTypes.string, homepage: PropTypes.string, + defaultPage: PropTypes.string, }; Form.defaultProps = { @@ -492,6 +490,7 @@ function mapStateToProps(state) { organizationName, hashSettings, enabledJoin, + defaultPage } = settings; return { @@ -502,13 +501,12 @@ function mapStateToProps(state) { greetingTitle: greetingSettings, hashSettings, enabledJoin, + defaultPage }; } export default connect(mapStateToProps, { login, setIsLoaded, - reloadPortalSettings, - getIsAuthenticated, - redirectToDefaultPage, + reloadPortalSettings })(withRouter(LoginForm)); diff --git a/web/ASC.Web.Common/src/store/auth/actions.js b/web/ASC.Web.Common/src/store/auth/actions.js index be692508ec..8d9e923473 100644 --- a/web/ASC.Web.Common/src/store/auth/actions.js +++ b/web/ASC.Web.Common/src/store/auth/actions.js @@ -1,5 +1,6 @@ import { default as api } from "../../api"; import { setWithCredentialsStatus } from "../../api/client"; +import history from "../../history"; export const LOGIN_POST = "LOGIN_POST"; export const SET_CURRENT_USER = "SET_CURRENT_USER"; @@ -148,7 +149,10 @@ export function getUser(dispatch) { export function getIsAuthenticated(dispatch) { return api.user .checkIsAuthenticated() - .then((res) => dispatch(setIsAuthenticated(res))); + .then((success) => { + dispatch(setIsAuthenticated(success)); + return success; + }); } export function getPortalSettings(dispatch) { @@ -204,7 +208,9 @@ export function logout() { return (dispatch) => { return api.user.logout().then(() => { setWithCredentialsStatus(false); - return dispatch(setLogout()); + dispatch(setLogout()); + + history.push("/login"); }); }; } @@ -229,11 +235,4 @@ export function getPortalPasswordSettings(dispatch, confirmKey = null) { export const reloadPortalSettings = () => { return (dispatch) => getPortalSettings(dispatch); -}; - -export function redirectToDefaultPage() { - return (_, getState) => { - const defaultPage = getState().settings.defaultPage; - setTimeout(() => window.location.replace(defaultPage), 0); - }; -} +}; \ No newline at end of file diff --git a/web/ASC.Web.Common/src/store/auth/reducer.js b/web/ASC.Web.Common/src/store/auth/reducer.js index 8ea36d29cb..dcf70e874d 100644 --- a/web/ASC.Web.Common/src/store/auth/reducer.js +++ b/web/ASC.Web.Common/src/store/auth/reducer.js @@ -17,7 +17,6 @@ import { SET_WIZARD_COMPLETED, SET_IS_AUTHENTICATED, } from "./actions"; -import isEmpty from "lodash/isEmpty"; import { LANGUAGE } from "../../constants"; const initialState = { @@ -153,6 +152,7 @@ const authReducer = (state = initialState, action) => { }); case LOGOUT: return Object.assign({}, initialState, { + isLoaded: true, settings: state.settings, }); case SET_WIZARD_COMPLETED: diff --git a/web/ASC.Web.Common/src/utils/index.js b/web/ASC.Web.Common/src/utils/index.js index 000cf467b6..cb5cbafb78 100644 --- a/web/ASC.Web.Common/src/utils/index.js +++ b/web/ASC.Web.Common/src/utils/index.js @@ -95,3 +95,13 @@ export function showLoader() { } export { withLayoutSize } from "./withLayoutSize"; + +export function tryRedirectTo(page) { + + if(window.location && window.location.pathname && window.location.pathname.indexOf(page) !== -1) + return false; + //TODO: check if we already on default page + window.location.replace(page); + + return true; +} \ No newline at end of file From 2baf8cbc76edd9434f2a1d0e7398edbec30a7ae7 Mon Sep 17 00:00:00 2001 From: AlexeySafronov Date: Fri, 4 Dec 2020 17:15:00 +0300 Subject: [PATCH 18/22] Fixed confirm link user creation --- web/ASC.Web.Client/src/App.js | 13 +++------- .../src/components/pages/Confirm/index.js | 23 ++++++++++++++--- .../Confirm/sub-components/createUser.js | 9 ++++--- .../src/helpers/confirmRoute.js | 5 ++-- .../src/store/confirm/actions.js | 22 +++++++++++++--- .../components/PrivateRoute/PrivateRoute.js | 2 +- .../src/components/PublicRoute/PublicRoute.js | 25 ++++++++++++++++--- 7 files changed, 71 insertions(+), 28 deletions(-) diff --git a/web/ASC.Web.Client/src/App.js b/web/ASC.Web.Client/src/App.js index 8ffca09b01..d159814081 100644 --- a/web/ASC.Web.Client/src/App.js +++ b/web/ASC.Web.Client/src/App.js @@ -39,8 +39,7 @@ class App extends React.Component { getUser, getModules, setIsLoaded, - getIsAuthenticated, - //defaultPage + getIsAuthenticated } = this.props; getIsAuthenticated() @@ -49,11 +48,6 @@ class App extends React.Component { if (!isAuthenticated) { requests.push(getPortalSettings()); } else if (!window.location.pathname.includes("confirm/EmailActivation")) { - - // debugger; - // if(utils.tryRedirectTo(defaultPage)) //TODO: Re-write redirect to defaultPage after get settings - // return; - requests.push(getUser()); requests.push(getPortalSettings()); requests.push(getModules()); @@ -114,12 +108,11 @@ class App extends React.Component { const mapStateToProps = (state) => { const { modules, isLoaded, settings } = state.auth; - const { organizationName, defaultPage } = settings; + const { organizationName } = settings; return { modules, isLoaded, - organizationName, - defaultPage + organizationName }; }; diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/index.js b/web/ASC.Web.Client/src/components/pages/Confirm/index.js index 6080a3f689..04672723c5 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/index.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/index.js @@ -2,9 +2,12 @@ import React, { Suspense, lazy, useEffect } from "react"; import { Route, Switch } from "react-router-dom"; import ConfirmRoute from "../../../helpers/confirmRoute"; import { I18nextProvider } from "react-i18next"; -import { Error404, utils } from "asc-web-common"; - +import { Error404, utils, store, PageLayout, Loaders } from "asc-web-common"; import { createI18N } from "../../../helpers/i18n"; +import { connect } from "react-redux"; + +const { getIsLoaded } = store.auth.selectors; + const i18n = createI18N({ page: "Confirm", localesPath: "pages/Confirm", @@ -23,13 +26,19 @@ const ChangePhoneForm = lazy(() => import("./sub-components/changePhone")); const ProfileRemoveForm = lazy(() => import("./sub-components/profileRemove")); const ChangeOwnerForm = lazy(() => import("./sub-components/changeOwner")); -const Confirm = ({ match }) => { +const Confirm = ({ match, isLoaded }) => { useEffect(() => { changeLanguage(i18n); }, []); //console.log("Confirm render"); return ( + !isLoaded ? + + + + : + @@ -80,4 +89,10 @@ const Confirm = ({ match }) => { ); }; -export default Confirm; +function mapStateToProps(state) { + return { + isLoaded: getIsLoaded(state) + }; +} + +export default connect(mapStateToProps)(Confirm); diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/createUser.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/createUser.js index 53fb649a76..1ed1a5978f 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/createUser.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/createUser.js @@ -19,7 +19,7 @@ import { createConfirmUser, } from "../../../../store/confirm/actions"; const { logout, login } = store.auth.actions; -const { createPasswordHash } = commonUtils; +const { createPasswordHash, tryRedirectTo } = commonUtils; const inputWidth = "400px"; const ConfirmContainer = styled.div` @@ -89,7 +89,7 @@ class Confirm extends React.PureComponent { onSubmit = () => { this.setState({ isLoading: true }, () => { - const { history, createConfirmUser, linkData, hashSettings } = this.props; + const { defaultPage, createConfirmUser, linkData, hashSettings } = this.props; const isVisitor = parseInt(linkData.emplType) === 2; this.setState({ errorText: "" }); @@ -142,7 +142,7 @@ class Confirm extends React.PureComponent { createConfirmUser(registerData, loginData, this.state.key) .then(() => { toastr.success("User has been created successfully"); - return history.push("/"); + tryRedirectTo(defaultPage); }) .catch((error) => { console.error("confirm error", error); @@ -368,6 +368,7 @@ function mapStateToProps(state) { settings: state.auth.settings.passwordSettings, greetingTitle: state.auth.settings.greetingSettings, hashSettings: state.auth.settings.hashSettings, + defaultPage: state.auth.settings.defaultPage }; } @@ -375,5 +376,5 @@ export default connect(mapStateToProps, { getConfirmationInfo, createConfirmUser, login, - logout, + logout })(withRouter(withTranslation()(CreateUserForm))); diff --git a/web/ASC.Web.Client/src/helpers/confirmRoute.js b/web/ASC.Web.Client/src/helpers/confirmRoute.js index 24667f8196..62982a1281 100644 --- a/web/ASC.Web.Client/src/helpers/confirmRoute.js +++ b/web/ASC.Web.Client/src/helpers/confirmRoute.js @@ -4,7 +4,8 @@ import { ValidationResult } from "./../helpers/constants"; import { Loader } from "asc-web-components"; import { connect } from "react-redux"; import { withRouter } from "react-router"; -import { api, utils, PageLayout } from "asc-web-common"; +import { api, utils, PageLayout, store } from "asc-web-common"; +const { isAuthenticated } = store.auth.selectors; const { checkConfirmLink } = api.user; const { getObjectByLocation } = utils; @@ -99,7 +100,7 @@ class ConfirmRoute extends React.Component { function mapStateToProps(state) { return { - isAuthenticated: state.auth.isAuthenticated, + isAuthenticated: isAuthenticated(state) }; } diff --git a/web/ASC.Web.Client/src/store/confirm/actions.js b/web/ASC.Web.Client/src/store/confirm/actions.js index c14645cf02..df1991fe7b 100644 --- a/web/ASC.Web.Client/src/store/confirm/actions.js +++ b/web/ASC.Web.Client/src/store/confirm/actions.js @@ -30,9 +30,25 @@ export function createConfirmUser(registerData, loginData, key) { return (dispatch) => { return api.people .createUser(data, key) - .then((user) => dispatch(setCurrentUser(user))) - .then(() => api.user.login(loginData.userName, loginData.passwordHash)) - .then(() => loadInitInfo(dispatch)); + .then((user) => { + dispatch(setCurrentUser(user)); + + }) + .then(() => { + const promise = new Promise((resolve, reject) => { + setTimeout(() => { + login(loginData.userName, loginData.passwordHash)(dispatch) + .then(() => { + resolve(loadInitInfo(dispatch)); + }) + .catch((e) => { + reject(e); + }) + }, 1000); + }); + + return promise; + }); }; } diff --git a/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js b/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js index 559e81f265..cb6cdf6615 100644 --- a/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js +++ b/web/ASC.Web.Common/src/components/PrivateRoute/PrivateRoute.js @@ -38,7 +38,7 @@ const PrivateRoute = ({ component: Component, ...rest }) => { return ( - + ); diff --git a/web/ASC.Web.Common/src/components/PublicRoute/PublicRoute.js b/web/ASC.Web.Common/src/components/PublicRoute/PublicRoute.js index 8e8146d0c6..1b537e0ea0 100644 --- a/web/ASC.Web.Common/src/components/PublicRoute/PublicRoute.js +++ b/web/ASC.Web.Common/src/components/PublicRoute/PublicRoute.js @@ -2,11 +2,24 @@ import React from "react"; import { Redirect, Route } from "react-router-dom"; import { connect } from "react-redux"; +import { getIsLoaded, isAuthenticated } from "../../store/auth/selectors"; +import PageLayout from "../PageLayout"; +import RectangleLoader from "../Loaders/RectangleLoader/RectangleLoader"; export const PublicRoute = ({ component: Component, ...rest }) => { - const { wizardToken, wizardCompleted, isAuthenticated } = rest; + const { wizardToken, wizardCompleted, isAuthenticated, isLoaded } = rest; const renderComponent = (props) => { + if(!isLoaded) { + return ( + + + + + + ); + } + if (isAuthenticated) { return ( { }; function mapStateToProps(state) { + const { settings } = state.auth; + const {wizardToken, wizardCompleted} = settings; return { - isAuthenticated: state.auth.isAuthenticated, - wizardToken: state.auth.settings.wizardToken, - wizardCompleted: state.auth.settings.wizardCompleted, + isAuthenticated: isAuthenticated(state), + isLoaded: getIsLoaded(state), + + wizardToken, + wizardCompleted, }; } From cd100eba852e22125da569c512914853966bb510 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 7 Dec 2020 09:43:40 +0300 Subject: [PATCH 19/22] Web: Client: Fixed redirect after actions --- .../Confirm/sub-components/activateEmail.js | 9 ++--- .../Confirm/sub-components/activateUser.js | 7 ++-- .../Confirm/sub-components/changeEmail.js | 18 ++++++---- .../Confirm/sub-components/changeOwner.js | 12 ++++--- .../Confirm/sub-components/changePassword.js | 11 +++--- .../Confirm/sub-components/changePhone.js | 2 +- .../src/store/confirm/actions.js | 35 ++++++++++++++----- 7 files changed, 62 insertions(+), 32 deletions(-) diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateEmail.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateEmail.js index 0ac65c1a3b..9ff4001f02 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateEmail.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateEmail.js @@ -5,13 +5,14 @@ import { Loader } from "asc-web-components"; import { PageLayout } from "asc-web-common"; import { connect } from "react-redux"; import PropTypes from "prop-types"; -import { store } from "asc-web-common"; +import { store, utils as commonUtils } from "asc-web-common"; import { changeEmail } from "../../../../store/confirm/actions"; const { logout } = store.auth.actions; +const { tryRedirectTo } = commonUtils; class ActivateEmail extends React.PureComponent { componentDidMount() { - const { history, logout, changeEmail, linkData } = this.props; + const { logout, changeEmail, linkData } = this.props; const [email, uid, key] = [ linkData.email, linkData.uid, @@ -20,11 +21,11 @@ class ActivateEmail extends React.PureComponent { logout(); changeEmail(uid, email, key) .then((res) => { - history.push(`/login/confirmed-email=${email}`); + tryRedirectTo(`/login/confirmed-email=${email}`); }) .catch((e) => { // console.log('activate email error', e); - history.push(`/login/error=${e}`); + tryRedirectTo(`/login/error=${e}`); }); } diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateUser.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateUser.js index 9746233533..dbdbf278c8 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateUser.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateUser.js @@ -19,7 +19,7 @@ import { activateConfirmUser, } from "../../../../store/confirm/actions"; const { EmployeeActivationStatus } = constants; -const { createPasswordHash } = commonUtils; +const { createPasswordHash, tryRedirectTo } = commonUtils; const inputWidth = "400px"; const ConfirmContainer = styled.div` @@ -82,7 +82,7 @@ class Confirm extends React.PureComponent { onSubmit = (e) => { this.setState({ isLoading: true }, function () { - const { activateConfirmUser, history, hashSettings } = this.props; + const { activateConfirmUser, hashSettings, defaultPage } = this.props; this.setState({ errorText: "" }); @@ -131,7 +131,7 @@ class Confirm extends React.PureComponent { this.state.userId, EmployeeActivationStatus.Activated ) - .then(() => history.push("/")) + .then(() => tryRedirectTo(defaultPage)) .catch((error) => { console.error("activate error", error); this.setState({ @@ -344,6 +344,7 @@ function mapStateToProps(state) { settings: state.auth.settings.passwordSettings, greetingTitle: state.auth.settings.greetingSettings, hashSettings: state.auth.settings.hashSettings, + defaultPage: state.auth.settings.defaultPage, }; } diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeEmail.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeEmail.js index 267d45ef64..8cf7e7bc2b 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeEmail.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeEmail.js @@ -2,10 +2,11 @@ import React from "react"; import { withRouter } from "react-router"; import { withTranslation } from "react-i18next"; import { Loader } from "asc-web-components"; -import { PageLayout } from "asc-web-common"; +import { PageLayout, utils as commonUtils } from "asc-web-common"; import { connect } from "react-redux"; import PropTypes from "prop-types"; import { changeEmail } from "../../../../store/confirm/actions"; +const { tryRedirectTo } = commonUtils; class ChangeEmail extends React.PureComponent { componentDidMount() { @@ -15,29 +16,33 @@ class ChangeEmail extends React.PureComponent { changeEmail(userId, email, key) .then((res) => { console.log("change client email success", res); - window.location.href = `${window.location.origin}/products/people/view/@self?email_change=success`; + tryRedirectTo( + `${window.location.origin}/products/people/view/@self?email_change=success` + ); }) .catch((e) => { console.log("change client email error", e); - window.location.href = `${window.location.origin}/error=${e}`; + tryRedirectTo(`${window.location.origin}/error=${e}`); }); } } componentDidUpdate() { - const { changeEmail, userId, isLoaded, linkData } = this.props; + const { changeEmail, userId, isLoaded, linkData, defaultPage } = this.props; if (isLoaded) { const [email, key] = [linkData.email, linkData.confirmHeader]; changeEmail(userId, email, key) .then((res) => { console.log("change client email success", res); - window.location.href = `${window.location.origin}/products/people/view/@self?email_change=success`; + tryRedirectTo( + `${window.location.origin}/products/people/view/@self?email_change=success` + ); }) .catch((e) => { console.log("change client email error", e); }); } else { - window.location.href = "/"; + tryRedirectTo(defaultPage); } } @@ -63,6 +68,7 @@ function mapStateToProps(state) { return { isLoaded: state.auth.isLoaded, userId: state.auth.user.id, + defaultPage: state.auth.settings.defaultPage, }; } diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeOwner.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeOwner.js index b22b10a24f..de0a4502c8 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeOwner.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changeOwner.js @@ -4,7 +4,8 @@ import { withTranslation } from "react-i18next"; import { connect } from "react-redux"; import styled from "styled-components"; import { Button, Text, toastr } from "asc-web-components"; -import { PageLayout } from "asc-web-common"; +import { PageLayout, utils as commonUtils } from "asc-web-common"; +const { tryRedirectTo } = commonUtils; const BodyStyle = styled.div` margin-top: 70px; @@ -58,11 +59,11 @@ class Form extends React.PureComponent { }; onRedirect = () => { - this.props.history.push("/"); + tryRedirectTo(this.props.defaultPage); }; onCancelClick = () => { - this.props.history.push("/"); + tryRedirectTo(this.props.defaultPage); }; render() { @@ -126,7 +127,10 @@ const ChangePasswordForm = (props) => ( ); function mapStateToProps(state) { - return { greetingTitle: state.auth.settings.greetingSettings }; + return { + greetingTitle: state.auth.settings.greetingSettings, + defaultPage: state.auth.settings.defaultPage, + }; } export default connect( diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePassword.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePassword.js index 535b04ade3..516cfe683d 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePassword.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePassword.js @@ -19,7 +19,7 @@ import { changePassword, } from "../../../../store/confirm/actions"; -const { createPasswordHash } = commonUtils; +const { createPasswordHash, tryRedirectTo } = commonUtils; const { logout } = store.auth.actions; const BodyStyle = styled.form` @@ -80,7 +80,7 @@ class Form extends React.PureComponent { onSubmit = (e) => { this.setState({ isLoading: true }, function () { const { userId, password, key } = this.state; - const { history, changePassword, hashSettings } = this.props; + const { changePassword, hashSettings, defaultPage } = this.props; let hasError = false; if (!this.state.passwordValid) { @@ -99,8 +99,8 @@ class Form extends React.PureComponent { changePassword(userId, hash, key) .then(() => this.props.logout()) .then(() => { - history.push("/"); toastr.success(this.props.t("ChangePasswordSuccess")); + tryRedirectTo(defaultPage); }) .catch((error) => { toastr.error(this.props.t(`${error}`)); @@ -110,10 +110,10 @@ class Form extends React.PureComponent { }; componentDidMount() { - const { getConfirmationInfo, history } = this.props; + const { getConfirmationInfo, defaultPage } = this.props; getConfirmationInfo(this.state.key).catch((error) => { toastr.error(this.props.t(`${error}`)); - history.push("/"); + tryRedirectTo(defaultPage); }); window.addEventListener("keydown", this.onKeyPress); @@ -221,6 +221,7 @@ function mapStateToProps(state) { isAuthenticated: state.auth.isAuthenticated, greetingTitle: state.auth.settings.greetingSettings, hashSettings: state.auth.settings.hashSettings, + defaultPage: state.auth.settings.defaultPage, }; } diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePhone.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePhone.js index 91eaaa97b3..0fa3ee2082 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePhone.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePhone.js @@ -50,7 +50,7 @@ const PhoneForm = (props) => { const buttonTranslation = `Enter number`; const onSubmit = () => { - console.log("onSubmit CHANGE"); + console.log("onSubmit CHANGE"); //TODO: Why do nothing? }; const onKeyPress = (target) => { diff --git a/web/ASC.Web.Client/src/store/confirm/actions.js b/web/ASC.Web.Client/src/store/confirm/actions.js index df1991fe7b..a93d0a9313 100644 --- a/web/ASC.Web.Client/src/store/confirm/actions.js +++ b/web/ASC.Web.Client/src/store/confirm/actions.js @@ -30,23 +30,25 @@ export function createConfirmUser(registerData, loginData, key) { return (dispatch) => { return api.people .createUser(data, key) - .then((user) => { + .then((user) => { dispatch(setCurrentUser(user)); - }) - .then(() => { + .then(() => { const promise = new Promise((resolve, reject) => { setTimeout(() => { - login(loginData.userName, loginData.passwordHash)(dispatch) + login( + loginData.userName, + loginData.passwordHash + )(dispatch) .then(() => { resolve(loadInitInfo(dispatch)); - }) + }) .catch((e) => { reject(e); - }) - }, 1000); + }); + }, 1000); }); - + return promise; }); }; @@ -72,7 +74,22 @@ export function activateConfirmUser( return api.people.updateActivationStatus(activationStatus, userId, key); }) .then((data) => { - return dispatch(login(loginData.userName, loginData.passwordHash)); + const promise = new Promise((resolve, reject) => { + setTimeout(() => { + login( + data.userName, + data.passwordHash + )(dispatch) + .then(() => { + resolve(loadInitInfo(dispatch)); + }) + .catch((e) => { + reject(e); + }); + }, 1000); + }); + + return promise; }) .then((data) => { return api.people.updateUser(changedData); From 049f7971f12afd107efbc4b70f8fcd4fd7d85fc0 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 7 Dec 2020 09:52:29 +0300 Subject: [PATCH 20/22] web: components: bump version --- web/ASC.Web.Components/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Components/package.json b/web/ASC.Web.Components/package.json index f274f3d949..5c0b5a24c7 100644 --- a/web/ASC.Web.Components/package.json +++ b/web/ASC.Web.Components/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-components", - "version": "1.0.489", + "version": "1.0.490", "description": "Ascensio System SIA component library", "license": "AGPL-3.0", "main": "dist/asc-web-components.js", From 830fbfb6a3b6972348533e86456b11b05c07263a Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 7 Dec 2020 09:52:39 +0300 Subject: [PATCH 21/22] web: common: bump version --- web/ASC.Web.Common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/package.json b/web/ASC.Web.Common/package.json index 7c6ccf0014..55761c3b75 100644 --- a/web/ASC.Web.Common/package.json +++ b/web/ASC.Web.Common/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-common", - "version": "1.0.284", + "version": "1.0.285", "description": "Ascensio System SIA common components and solutions library", "license": "AGPL-3.0", "files": [ From 4147d2f31ab1ceb96e6716e52d0c6039a2850b00 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Mon, 7 Dec 2020 11:11:04 +0300 Subject: [PATCH 22/22] Web: Fixed temp loaders --- products/ASC.Files/Client/public/index.html | 11 ----- products/ASC.Files/Client/src/App.js | 45 ++++++++--------- products/ASC.People/Client/public/index.html | 11 ----- products/ASC.People/Client/src/App.js | 45 ++++++++--------- web/ASC.Web.Client/public/index.html | 11 ----- web/ASC.Web.Client/src/App.js | 52 ++++++++++---------- web/ASC.Web.Common/src/utils/index.js | 33 +++++++++---- 7 files changed, 96 insertions(+), 112 deletions(-) diff --git a/products/ASC.Files/Client/public/index.html b/products/ASC.Files/Client/public/index.html index 31d5f4914c..d34eaf8bbe 100644 --- a/products/ASC.Files/Client/public/index.html +++ b/products/ASC.Files/Client/public/index.html @@ -239,16 +239,5 @@ To begin the development, run `npm start` or `yarn start`. To create a production bundle, use `npm run build` or `yarn build`. --> - diff --git a/products/ASC.Files/Client/src/App.js b/products/ASC.Files/Client/src/App.js index 735b4dfc19..9d1b7506b5 100644 --- a/products/ASC.Files/Client/src/App.js +++ b/products/ASC.Files/Client/src/App.js @@ -42,8 +42,6 @@ class App extends React.Component { } componentDidMount() { - utils.removeTempContent(); - const { setModuleInfo, getUser, @@ -57,28 +55,31 @@ class App extends React.Component { setModuleInfo(); getIsAuthenticated().then((isAuthenticated) => { + if (!isAuthenticated) { + utils.updateTempContent(); + return setIsLoaded(); + } else { + utils.updateTempContent(isAuthenticated); + } - if (!isAuthenticated) { - return setIsLoaded(); - } + const requests = this.isEditor + ? [getUser()] + : [ + getUser(), + getPortalSettings(), + getModules(), + getPortalCultures(), + fetchTreeFolders(), + ]; - const requests = this.isEditor - ? [getUser()] - : [ - getUser(), - getPortalSettings(), - getModules(), - getPortalCultures(), - fetchTreeFolders(), - ]; - - Promise.all(requests) - .catch((e) => { - toastr.error(e); - }) - .finally(() => { - setIsLoaded(); - }); + Promise.all(requests) + .catch((e) => { + toastr.error(e); + }) + .finally(() => { + utils.updateTempContent(); + setIsLoaded(); + }); }); } diff --git a/products/ASC.People/Client/public/index.html b/products/ASC.People/Client/public/index.html index 53c343eb69..d941ccc1ba 100644 --- a/products/ASC.People/Client/public/index.html +++ b/products/ASC.People/Client/public/index.html @@ -239,16 +239,5 @@ To begin the development, run `npm start` or `yarn start`. To create a production bundle, use `npm run build` or `yarn build`. --> - diff --git a/products/ASC.People/Client/src/App.js b/products/ASC.People/Client/src/App.js index 3b49cca27b..4a8168a533 100644 --- a/products/ASC.People/Client/src/App.js +++ b/products/ASC.People/Client/src/App.js @@ -42,8 +42,6 @@ const GroupAction = lazy(() => import("./components/pages/GroupAction"));*/ class App extends React.Component { componentDidMount() { - utils.removeTempContent(); - const { setModuleInfo, getUser, @@ -59,28 +57,31 @@ class App extends React.Component { setModuleInfo(); getIsAuthenticated().then((isAuthenticated) => { + if (!isAuthenticated) { + utils.updateTempContent(); + return setIsLoaded(); + } else { + utils.updateTempContent(isAuthenticated); + } - if (!isAuthenticated) { - return setIsLoaded(); - } + const requests = [ + getUser(), + getPortalSettings(), + getModules(), + getPortalPasswordSettings(), + getPortalCultures(), + fetchGroups(), + fetchPeople(), + ]; - const requests = [ - getUser(), - getPortalSettings(), - getModules(), - getPortalPasswordSettings(), - getPortalCultures(), - fetchGroups(), - fetchPeople(), - ]; - - Promise.all(requests) - .catch((e) => { - toastr.error(e); - }) - .finally(() => { - setIsLoaded(); - }); + Promise.all(requests) + .catch((e) => { + toastr.error(e); + }) + .finally(() => { + utils.updateTempContent(); + setIsLoaded(); + }); }); } diff --git a/web/ASC.Web.Client/public/index.html b/web/ASC.Web.Client/public/index.html index 69a4773dfb..42fa3983a4 100644 --- a/web/ASC.Web.Client/public/index.html +++ b/web/ASC.Web.Client/public/index.html @@ -212,16 +212,5 @@ To begin the development, run `npm start` or `yarn start`. To create a production bundle, use `npm run build` or `yarn build`. --> - diff --git a/web/ASC.Web.Client/src/App.js b/web/ASC.Web.Client/src/App.js index d159814081..a9880831b7 100644 --- a/web/ASC.Web.Client/src/App.js +++ b/web/ASC.Web.Client/src/App.js @@ -27,41 +27,43 @@ const { getUser, getPortalSettings, getModules, - getIsAuthenticated + getIsAuthenticated, } = CommonStore.auth.actions; class App extends React.Component { componentDidMount() { - utils.removeTempContent(); - const { getPortalSettings, getUser, getModules, setIsLoaded, - getIsAuthenticated + getIsAuthenticated, } = this.props; getIsAuthenticated() - .then((isAuthenticated) => { - const requests = []; - if (!isAuthenticated) { - requests.push(getPortalSettings()); - } else if (!window.location.pathname.includes("confirm/EmailActivation")) { - requests.push(getUser()); - requests.push(getPortalSettings()); - requests.push(getModules()); - } - - Promise.all(requests) - .catch((e) => { - toastr.error(e); - }) - .finally(() => { - setIsLoaded(); - }); - }) - .catch((err) => toastr.error(err)); + .then((isAuthenticated) => { + if (isAuthenticated) utils.updateTempContent(isAuthenticated); + const requests = []; + if (!isAuthenticated) { + requests.push(getPortalSettings()); + } else if ( + !window.location.pathname.includes("confirm/EmailActivation") + ) { + requests.push(getUser()); + requests.push(getPortalSettings()); + requests.push(getModules()); + } + + Promise.all(requests) + .catch((e) => { + toastr.error(e); + }) + .finally(() => { + utils.updateTempContent(); + setIsLoaded(); + }); + }) + .catch((err) => toastr.error(err)); } render() { @@ -112,7 +114,7 @@ const mapStateToProps = (state) => { return { modules, isLoaded, - organizationName + organizationName, }; }; @@ -122,7 +124,7 @@ const mapDispatchToProps = (dispatch) => { getPortalSettings: () => getPortalSettings(dispatch), getUser: () => getUser(dispatch), getModules: () => getModules(dispatch), - setIsLoaded: () => dispatch(setIsLoaded(true)) + setIsLoaded: () => dispatch(setIsLoaded(true)), }; }; diff --git a/web/ASC.Web.Common/src/utils/index.js b/web/ASC.Web.Common/src/utils/index.js index cb5cbafb78..8c67234525 100644 --- a/web/ASC.Web.Common/src/utils/index.js +++ b/web/ASC.Web.Common/src/utils/index.js @@ -68,10 +68,20 @@ export function createPasswordHash(password, hashSettings) { return hash; } -export function removeTempContent() { - const tempElm = document.getElementById("temp-content"); - if (tempElm) { - tempElm.outerHTML = ""; +export function updateTempContent(isAuth = false) { + if (isAuth) { + let el = document.getElementById("burger-loader-svg"); + let el1 = document.getElementById("logo-loader-svg"); + let el2 = document.getElementById("avatar-loader-svg"); + + el.style.display = "block"; + el1.style.display = "block"; + el2.style.display = "block"; + } else { + const tempElm = document.getElementById("temp-content"); + if (tempElm) { + tempElm.outerHTML = ""; + } } } @@ -97,11 +107,14 @@ export function showLoader() { export { withLayoutSize } from "./withLayoutSize"; export function tryRedirectTo(page) { - - if(window.location && window.location.pathname && window.location.pathname.indexOf(page) !== -1) + if ( + window.location && + window.location.pathname && + window.location.pathname.indexOf(page) !== -1 + ) return false; - //TODO: check if we already on default page - window.location.replace(page); + //TODO: check if we already on default page + window.location.replace(page); - return true; -} \ No newline at end of file + return true; +}