This repository has been archived by the owner on Jul 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
1 changed file
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | |
<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}/> | ||
|
@@ -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> | ||
) | ||
} | ||
|