From 5c7de36ac78998bd3943b2c41c1148f928a25a2e Mon Sep 17 00:00:00 2001 From: clay53 Date: Wed, 16 Jan 2019 22:33:10 -0500 Subject: [PATCH] Achieved adequate progress on issue #36, Fixes issue #36 --- src/components/index.js | 56 +++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/src/components/index.js b/src/components/index.js index 2da17a2..c9e2ac9 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -23,7 +23,13 @@ import ReactGA from 'react-ga'; ReactGA.initialize(config.trackingId); function checkPathForBlocks(blockedPages, path) { - return true; + for (var i in blockedPages) { + var page = blockedPages[i]; + if (path.startsWith(page)) { + return true; + } + } + return false; } export default class App extends Component { @@ -32,9 +38,15 @@ export default class App extends Component { this.state = { currentUser: null, displayName: "", + networkAdminExists: false, + isNetworkAdmin: false, ip: "", + blockedPages: [], loading: true } + + this.unblockPage = this.unblockPage.bind(this); + this.blockPage = this.blockPage.bind(this); } componentDidMount () { @@ -57,11 +69,40 @@ export default class App extends Component { fetch('https://api.ipify.org?format=json').then((response) => { return response.json(); }).then((data) => { + firebase.firestore().collection("network-admin").doc(data.ip).get().then((documentSnapshot) => { + var docData = documentSnapshot.data(); + this.setState({ + ip: data.ip, + networkAdminExists: documentSnapshot.exists, + networkAdminUID: documentSnapshot.exists ? docData['admin-uid'] : "", + blockedPages: documentSnapshot.exists ? docData.blockedPages : [], + loading: false + }) + }); + }); + } + + blockPage (event) { + var newBlockedPages = this.state.blockedPages.slice(); + newBlockedPages.push(window.location.pathname); + firebase.firestore().collection("network-admin").doc(this.state.ip).update({ + blockedPages: newBlockedPages + }).then(() => { this.setState({ - ip: data, - loading: false + blockedPages: newBlockedPages }) - }); + }) + } + unblockPage (event) { + var newBlockedPages = this.state.blockedPages.slice(); + newBlockedPages.splice(newBlockedPages.indexOf(window.location.pathname), 1); + firebase.firestore().collection("network-admin").doc(this.state.ip).update({ + blockedPages: newBlockedPages + }).then(() => { + this.setState({ + blockedPages: newBlockedPages + }) + }) } componentDidUpdate () { @@ -86,9 +127,10 @@ export default class App extends Component {
  • Patreon
  • Discord
  • YouTube
  • +
  • {this.state.currentUser != null && this.state.currentUser.uid === this.state.networkAdminUID ? (checkPathForBlocks(this.state.blockedPages, window.location.pathname) ? : ) : null}
  • {!this.state.loading ? - (checkPathForBlocks(this.state.blockedPages, window.location.pathname) ?
    + (!checkPathForBlocks(this.state.blockedPages, window.location.pathname) ?
    @@ -115,10 +157,10 @@ export default class App extends Component { Loading...
    } -
    + {(!window.location.pathname.startsWith("/games/") || !window.location.pathname.startsWith("/softwares/")) && !window.location.pathname.includes("/Web/") ?

    Are you network admin and would like to control what pages users can view on the site? If so, please contact network@claytondoesthings.xyz with adequate proof of position as well as a valid IP address.

    -
    +
    : null}
    ) }