Skip to content

Commit

Permalink
authorization_required
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Apr 24, 2024
1 parent deb908a commit a0af3bf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/components/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,7 @@ HTML {
display: none;
}
}

.reveal-blurring {
backdrop-filter: blur(8px);
}
9 changes: 7 additions & 2 deletions app/components/modules/Modals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -56,6 +56,7 @@ class Modals extends React.Component {
render() {
const {
show_login_modal,
loginBlurring,
show_confirm_modal,
show_donate_modal,
show_gift_nft_modal,
Expand Down Expand Up @@ -84,9 +85,11 @@ class Modals extends React.Component {
return n;
}) : [];

const loginClass = loginBlurring ? 'reveal-blurring' : undefined

return (
<div>
{show_login_modal && <Reveal onBackdropClick={this.onLoginBackdropClick} onHide={hideLogin} show={show_login_modal}>
{show_login_modal && <Reveal overlayClassName={loginClass} onBackdropClick={this.onLoginTryClose} onEscapeKeyDown={this.onLoginTryClose} onHide={hideLogin} show={show_login_modal}>
<LoginForm onCancel={hideLogin} />
</Reveal>}
{show_confirm_modal && <Reveal onHide={hideConfirm} show={show_confirm_modal}>
Expand Down Expand Up @@ -129,9 +132,11 @@ export default connect(
state => {
const loginDefault = state.user.get('loginDefault');
const loginUnclosable = loginDefault && loginDefault.get('unclosable');
const loginBlurring = loginDefault && loginDefault.get('blurring')
return {
show_login_modal: state.user.get('show_login_modal'),
loginUnclosable,
loginBlurring,
show_confirm_modal: state.transaction.get('show_confirm_modal'),
show_donate_modal: state.user.get('show_donate_modal'),
show_gift_nft_modal: state.user.get('show_gift_nft_modal'),
Expand Down
14 changes: 14 additions & 0 deletions app/redux/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ 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,
blurring: true
}
})
}
},
{
action: 'SHOW_LOGIN',
reducer: (state, {payload}) => {
Expand Down
1 change: 1 addition & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ global.$STM_Config = {
forums: config.get('forums'),
blocked_users,
blocked_posts,
authorization_required: config.has('authorization_required') && config.get('authorization_required'),
ui_version: version || '1.0-unknown',
};

Expand Down
13 changes: 12 additions & 1 deletion shared/UniversalRender.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ 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';
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';
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';
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a0af3bf

Please sign in to comment.