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 57b7cc0
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/components/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ HTML {
filter: none;
-webkit-filter: none;
}
.blurring {
filter: blur(5px);
}

.App__announcement {
.logo-icon {
Expand Down Expand Up @@ -195,3 +198,7 @@ HTML {
display: none;
}
}

.reveal-blurring {
backdrop-filter: blur(3px);
}
17 changes: 14 additions & 3 deletions app/components/cards/PostSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { authRegisterUrl, } from 'app/utils/AuthApiClient'
import { hideSummary } from 'app/utils/ContentAccess'
import extractContent from 'app/utils/ExtractContent'
import {authorNameAndRep} from 'app/utils/ComponentFormatters'
import { randomString } from 'app/utils/helpers'
import { addHighlight, unsubscribePost } from 'app/utils/NotifyApiClient'
import { detransliterate } from 'app/utils/ParsersAndFormatters'
import { proxifyImageUrl } from 'app/utils/ProxifyUrl'
Expand Down Expand Up @@ -86,7 +87,8 @@ class PostSummary extends React.Component {
state.revealNsfw !== this.state.revealNsfw ||
props.visited !== this.props.visited ||
props.gray !== this.props.gray ||
props.encrypted !== this.props.encrypted
props.encrypted !== this.props.encrypted ||
props.loginBlurring !== this.props.loginBlurring
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -150,7 +152,7 @@ class PostSummary extends React.Component {
const {currentCategory, thumbSize, onClick} = this.props;
const {post, content, pending_payout, total_payout, cashout_time, blockEye} = this.props;
const {account} = this.props;
const {nsfwPref, username} = this.props
const {nsfwPref, username, loginBlurring} = this.props
if (!content) return null;

let reblogged_by;
Expand Down Expand Up @@ -225,6 +227,11 @@ class PostSummary extends React.Component {
comments_link = p.link + '#comments';
}

if (loginBlurring) {
title_text = randomString(title_text)
desc = randomString(desc)
}

if (title_link_url.includes('fm-') && $STM_Config.forums) {
let parts = title_link_url.split('/');
for (let [_id, forum] of Object.entries($STM_Config.forums)) {
Expand Down Expand Up @@ -362,6 +369,7 @@ class PostSummary extends React.Component {
}
const commentClasses = []
if(gray) commentClasses.push('downvoted') // rephide
if (loginBlurring) commentClasses.push('blurring')

total_search = total_search ? <span class="strike" style={{ fontSize: '1rem', paddingBottom: '1rem' }}>
{tt('g.and_more_search_posts_COUNT', { COUNT: total_search })}
Expand Down Expand Up @@ -442,9 +450,12 @@ export default connect(
const stats = content.get('stats', Map()).toJS()
gray = stats.gray
}
const loginDefault = state.user.get('loginDefault')
const loginBlurring = loginDefault && loginDefault.get('blurring')
return {
post, content, gray, pending_payout, total_payout, event_count, encrypted,
username: state.user.getIn(['current', 'username']) || state.offchain.get('account')
username: state.user.getIn(['current', 'username']) || state.offchain.get('account'),
loginBlurring
};
},

Expand Down
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
13 changes: 13 additions & 0 deletions app/redux/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ export default createModule({
name: 'user',
initialState: defaultState,
transformations: [
{
action: 'REQUIRE_LOGIN',
reducer: (state, {payload}) => {
return state.merge({
show_login_modal: true,
loginDefault: {
unclosable: true,
cancelIsRegister: true,
blurring: true
}
})
}
},
{
action: 'SHOW_LOGIN',
reducer: (state, {payload}) => {
Expand Down
15 changes: 15 additions & 0 deletions app/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
export function randomString(str) {
let res = ''
const abc = 'abcdefghijklmnopqrstuvwxz'
for (let i = 0; i < str.length; ++i) {
const c = str[i]
if (c === ' ') {
res += c
continue
}
const nc = abc[Math.floor(Math.random() * abc.length)]
res += nc
}
return res
}

export function encode(str) {
let hash = 0, chr;
if (str.length === 0) return hash;
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 57b7cc0

Please sign in to comment.