Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Commit

Permalink
Achieved adequate progress on issue #36, Fixes issue #36
Browse files Browse the repository at this point in the history
  • Loading branch information
clay53 committed Jan 17, 2019
1 parent 221d174 commit 5c7de36
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -86,9 +127,10 @@ export default class App extends Component {
<li style={{float: "right"}}><a className={classNames("clickable", "img")} href="https://www.patreon.com/ClaytonDoesThings"><img alt="Patreon" src="https://i1.wp.com/www.jcourseywillis.com/wp-content/uploads/2016/10/patreon_logo_black.png?fit=300%2C300&ssl=1" height="42" style={{filter: "invert(100%)"}}/></a></li>
<li style={{float: "right"}}><a className={classNames("clickable", "img")} href="https://discordapp.com/invite/nSGT8BJ"><img alt="Discord" src="https://www.freeiconspng.com/uploads/discord-black-icon-1.png" height="42" style={{filter: "invert(100%)"}}/></a></li>
<li style={{float: "right"}}><a className={classNames("clickable", "img")} href="https://www.youtube.com/channel/UChXdVQ8mm8UQBir87KaRgTQ"><img alt="YouTube" src="https://image.flaticon.com/icons/png/512/25/25178.png" height="42" style={{filter: "invert(100%)"}}/></a></li>
<li style={{float: "right"}}>{this.state.currentUser != null && this.state.currentUser.uid === this.state.networkAdminUID ? (checkPathForBlocks(this.state.blockedPages, window.location.pathname) ? <input type="button" value="Unblock Current Page" onClick={this.unblockPage}/> : <input type="button" value="Block Current Page" onClick={this.blockPage}/>) : null}</li>
</ul>
{!this.state.loading ?
(checkPathForBlocks(this.state.blockedPages, window.location.pathname) ? <div>
(!checkPathForBlocks(this.state.blockedPages, window.location.pathname) ? <div>
<Route path="/" exact component={Home}/>
<Route path="/games" exact component={Games}/>
<Route path="/games/:id/:platform/:version/" exact component={GameFrame}/>
Expand All @@ -115,10 +157,10 @@ export default class App extends Component {
<span>Loading...</span>
</div>
}
<div className="centered">
{(!window.location.pathname.startsWith("/games/") || !window.location.pathname.startsWith("/softwares/")) && !window.location.pathname.includes("/Web/") ? <div className="centered">
<hr/>
<p>Are you network admin and would like to control what pages users can view on the site? If so, please contact [email protected] with adequate proof of position as well as a valid IP address.</p>
</div>
</div> : null}
</div>
)
}
Expand Down

0 comments on commit 5c7de36

Please sign in to comment.