From abdf46d4d271b0924232435d6b8a8447f3981d77 Mon Sep 17 00:00:00 2001 From: 1aerostorm Date: Wed, 24 Apr 2024 13:20:58 +0300 Subject: [PATCH] authorization_required --- app/components/modules/Modals.jsx | 4 ++-- app/redux/User.js | 13 +++++++++++++ shared/UniversalRender.jsx | 13 ++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/components/modules/Modals.jsx b/app/components/modules/Modals.jsx index 547d18a42..10d5c4a82 100644 --- a/app/components/modules/Modals.jsx +++ b/app/components/modules/Modals.jsx @@ -47,7 +47,7 @@ class Modals extends React.Component { this.shouldComponentUpdate = shouldComponentUpdate(this, 'Modals'); } - onLoginBackdropClick = (e) => { + onLoginTryClose = (e) => { const { loginUnclosable } = this.props; if (loginUnclosable) throw new Error('Closing login modal is forbidden here'); @@ -86,7 +86,7 @@ class Modals extends React.Component { return (
- {show_login_modal && + {show_login_modal && } {show_confirm_modal && diff --git a/app/redux/User.js b/app/redux/User.js index 49c4c5c59..2d0782cf1 100644 --- a/app/redux/User.js +++ b/app/redux/User.js @@ -33,6 +33,19 @@ export default createModule({ name: 'user', initialState: defaultState, transformations: [ + { + action: 'REQUIRE_LOGIN', + reducer: (state, {payload}) => { + console.log('ACT-----') + return state.merge({ + show_login_modal: true, + loginDefault: { + unclosable: true, + cancelIsRegister: true + } + }) + } + }, { action: 'SHOW_LOGIN', reducer: (state, {payload}) => { diff --git a/shared/UniversalRender.jsx b/shared/UniversalRender.jsx index ffa71cfac..2236b97a6 100644 --- a/shared/UniversalRender.jsx +++ b/shared/UniversalRender.jsx @@ -11,7 +11,6 @@ import { match, applyRouterMiddleware } from 'react-router'; -import * as api from 'app/utils/APIWrapper' import { Provider } from 'react-redux'; import RootRoute from 'app/RootRoute'; import {createStore, applyMiddleware, compose} from 'redux'; @@ -19,6 +18,8 @@ import { browserHistory } from 'react-router'; import { useScroll } from 'react-router-scroll'; import createSagaMiddleware from 'redux-saga'; import { syncHistoryWithStore } from 'react-router-redux'; + +import * as api from 'app/utils/APIWrapper' import rootReducer from 'app/redux/RootReducer'; import rootSaga from 'app/redux/RootSaga'; import {component as NotFound} from 'app/components/pages/NotFound'; @@ -26,6 +27,7 @@ import extractMeta from 'app/utils/ExtractMeta'; import Translator from 'app/Translator'; import getState from 'app/utils/StateBuilder'; import {routeRegex} from "app/ResolveRoute"; +import session from 'app/utils/session' import {contentStats} from 'app/utils/StateFunctions' import {APP_NAME, SEO_TITLE} from 'app/client_config'; import constants from 'app/redux/constants'; @@ -80,6 +82,9 @@ export async function serverRender({ if (process.env.BROWSER) { const store = createStore(rootReducer, initial_state, middleware); + if (!session.load().currentName && $STM_Config.authorization_required) { + store.dispatch({type: 'user/REQUIRE_LOGIN', payload: {}}); + } // sagaMiddleware.run(PollDataSaga).done // .then(() => console.log('PollDataSaga is finished')) // .catch(err => console.log('PollDataSaga is finished with error', err)); @@ -161,6 +166,9 @@ export async function serverRender({ offchain.server_location = location; serverStore = createStore(rootReducer, { global: onchain, offchain}); + if (!offchain.account && $STM_Config.authorization_required) { + serverStore.dispatch({type: 'user/REQUIRE_LOGIN', payload: {}}); + } serverStore.dispatch({type: '@@router/LOCATION_CHANGE', payload: {pathname: location}}); // TODO: maybe use request to golosnotify to fetch counters? /*if (offchain.account) { @@ -221,6 +229,9 @@ export async function serverRender({ export function clientRender(initialState) { const store = createStore(rootReducer, initialState, middleware); + if (!session.load().currentName && $STM_Config.authorization_required) { + store.dispatch({type: 'user/REQUIRE_LOGIN', payload: {}}); + } sagaMiddleware.run(rootSaga) const history = syncHistoryWithStore(browserHistory, store);