Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ app.use(async (req, res, next) => {
(
req.path === '/api/discord/login' ||
req.path === '/login' ||
req.path === '/blocked' ||
(config.homePage && req.path === '/home')
)
) {
Expand Down
6 changes: 6 additions & 0 deletions src/routes/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ router.get('/callback', catchAsyncErrors(async (req, res) => {
req.session.username = `${user.username}#${user.discriminator}`;
const perms = await DiscordClient.getPerms(user);
req.session.perms = perms;
const blocked = perms.blocked;
const valid = perms.map !== false;
req.session.valid = valid;
req.session.save();
if (valid) {
console.log(user.id, 'Authenticated successfully.');
await DiscordClient.sendMessage(config.discord.logChannelId, `${user.username}#${user.discriminator} (${user.id}) Authenticated successfully.`);
res.redirect(`/?token=${response.data.access_token}`);
} else if (blocked) {
// User is in blocked Discord server(s)
console.warn(user.id, 'Blocked due to', blocked);
await DiscordClient.sendMessage(config.discord.logChannelId, `${user.username}#${user.discriminator} (${user.id}) Blocked due to ${blocked}.`);
res.redirect('/blocked');
} else {
// Not in Discord server(s) and/or have required roles to view map
console.warn(user.id, 'Not authorized to access map');
Expand Down
10 changes: 10 additions & 0 deletions src/routes/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ if (config.homePage) {
});
}

router.get('/blocked', (req, res) => {
const data = {};
data.discord_invite = config.discord.invite;
if (req.session.username) {
data.guild_name = req.session.perms.blocked;
data.username = req.session.username;
}
res.render('blocked', data);
});

// Location endpoints
router.get('/@/:lat/:lon', async (req, res) => {
res.setHeader('Content-Type', 'text/html');
Expand Down
7 changes: 4 additions & 3 deletions src/services/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DiscordClient {
async getGuilds() {
const guilds = await oauth.getUserGuilds(this.accessToken);
const guildIds = Array.from(guilds, x => BigInt(x.id).toString());
return guildIds;
return [guildIds, guilds];
}

async getUserRoles(guildId, userId) {
Expand Down Expand Up @@ -74,7 +74,7 @@ class DiscordClient {
}

async getPerms(user) {
const perms = {
var perms = {
map: false,
pokemon: false,
raids: false,
Expand All @@ -94,7 +94,7 @@ class DiscordClient {
weather: false,
devices: false
};
const guilds = await this.getGuilds();
const [guilds, guildsFull] = await this.getGuilds();
if (config.discord.allowedUsers.includes(user.id)) {
Object.keys(perms).forEach((key) => perms[key] = true);
console.log(`User ${user.username}#${user.discriminator} (${user.id}) in allowed users list, skipping guild and role check.`);
Expand All @@ -108,6 +108,7 @@ class DiscordClient {
if (guilds.includes(guildId)) {
// If so, user is not granted access
blocked = true;
perms["blocked"] = guildsFull.find(x => x.id === guildId).name;
break;
}
}
Expand Down
100 changes: 100 additions & 0 deletions src/views/blocked.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html,
body {
height: 85%;
width: 100%;
margin: 0px;
background-color: #2c2f33;
background-image: url('/img/discord.png');
}

.background {
background-image:url("/img/landing.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 95%;
border: 2px solid #7289da;
display: block;
margin-left: auto;
margin-right: auto;
}

#transbox {
background-color:rgba(255,255,255,0.8);
padding:20px;
}

.title {
text-align:center;
font-size: 2em;
color: #3C5FA3;
}

.container {
width: 90%;
margin: 0 auto;
padding: 30px;
}

.clearfix:after {
visibility:hidden;
display:block;
content:"";
clear:both;
height:0;
}

.description {
text-align:center;
opacity: 0.5;
color: #000000;
margin-left: 10px;
margin-bottom: 10px;
white-space: pre-wrap;
}

.make-center {
text-align: center;
padding: 20px 0;
}

.square_btn{
display: inline-block;
padding: 7px 20px;
border-radius: 25px;
text-decoration: none;
color: #FFF;
background-image: -webkit-linear-gradient(45deg, #7289da 0%, #4d6cdb 100%);
background-image: linear-gradient(45deg, #7289da 0%, #4d6cdb 100%);
transition: .4s;
}

.square_btn:hover {
background-image: -webkit-linear-gradient(45deg, #7289da 0%, #3659d8 100%);
background-image: linear-gradient(45deg, #7289da 0%, #3659d8 100%);
}
</style>
</head>
<body>
<div class="container clearfix background">
<div id="transbox">
<title>Access denied</title>
<div class="title">Access denied!</div>
<div class="description">{{username}} has been blocked for being a member of {{guild_name}}.
Please join our discord for more info.</div>
<div class="make-center">
<a href="/login" class="square_btn">Login</a><a href="{{discord_invite}}" class="square_btn">Join Our Discord</a>
</div>
</div>
</div>
</body>
</body>
</html>

<!--created by anonymous All images are copyright and belong to their respective owners,
this document is for educational purpose-->
199 changes: 99 additions & 100 deletions src/views/home.mustache
Original file line number Diff line number Diff line change
@@ -1,100 +1,99 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html,
body {
height: 80%;
width: 100%;
margin: 0px;
background-color: #2c2f33;
background-image: url('/img/discord.png');
}

.title {
font-size: 2em;
color: #ffffff;
margin-left: 10px;
}

.description {
opacity: 0.5;
color: #ffffff;
margin-left: 10px;
margin-bottom: 10px;
}

.discord-login {
min-width: 7em;
margin-top: 2em;
margin-right: 0em;
padding: 0.5em 2em;
outline: none;
border: 2px solid #7289da;
border-radius: 8em;
color: #7289da;
cursor: pointer;
transition-duration: 0.2s;
font-size: 0.95em;
font-family: 'Righteous';
margin-left: 10px;
}

.discord-login--active {
background-color: #7289da;
border: 2px solid #7289da;
color: white;
}

.discord-login--active:hover {
box-shadow: 0px 0px 10px 1px rgba(114,137,218,1);
color: #2c2f33;
}

.discord-join {
min-width: 7em;
margin-top: 2em;
margin-right: 0em;
padding: 0.5em 2em;
outline: none;
border: 2px solid #7289da;
background-color: transparent;
border-radius: 8em;
color: #7289da;
cursor: pointer;
transition-duration: 0.2s;
font-size: 0.95em;
font-family: 'Righteous';
margin-left: 10px;
}

.discord-join:hover {
color: white;
}

img {
width: 98%;
border: 2px solid #7289da;
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 5px;
margin-bottom: 3px;
vertical-align: middle;
}
</style>
</head>
<body>
<img src="/img/landing.png" >
<div class="title">WELCOME!</div>
<div class="description">The best place to find pokemon</div>
<div class="description">Please login or join discord for more info</div>
<a href="/login" class="discord-login discord-login--active">Login</a>
<a href="{{discord_invite}}" class="discord-join">Join Our Discord</a>
</div>
</body>
</html>

<!--created by anonymous All images are copyright and belong to their respective owners,
this document is for educational purpose-->
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html,
body {
height: 85%;
width: 100%;
margin: 0px;
background-color: #2c2f33;
background-image: url('/img/discord.png');
}

.background {
background-image:url("/img/landing.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 95%;
border: 2px solid #7289da;
display: block;
margin-left: auto;
margin-right: auto;
}

#transbox {
background-color:rgba(255,255,255,0.8);
padding:20px;
}

.title {
text-align:center;
font-size: 2em;
color: #3C5FA3;
}

.container {
width: 90%;
margin: 0 auto;
padding: 30px;
}

.clearfix:after {
visibility:hidden;
display:block;
content:"";
clear:both;
height:0;
}

.description {
text-align:center;
opacity: 0.5;
color: #000000;
margin-left: 10px;
margin-bottom: 10px;
white-space: pre-wrap;
}

.make-center {
text-align: center;
padding: 20px 0;
}

.square_btn{
display: inline-block;
padding: 7px 20px;
border-radius: 25px;
text-decoration: none;
color: #FFF;
background-image: -webkit-linear-gradient(45deg, #7289da 0%, #4d6cdb 100%);
background-image: linear-gradient(45deg, #7289da 0%, #4d6cdb 100%);
transition: .4s;
}

.square_btn:hover {
background-image: -webkit-linear-gradient(45deg, #7289da 0%, #3659d8 100%);
background-image: linear-gradient(45deg, #7289da 0%, #3659d8 100%);
}
</style>
</head>
<body>
<div class="container clearfix background">
<div id="transbox">
<title>Welcome</title>
<div class="title">Welcome</div>
<div class="description">The best place to find pokemon.</div>
<div class="description">Please login or join discord for more info...</div>
<div class="make-center">
<a href="/login" class="square_btn">Login</a><a href="{{discord_invite}}" class="square_btn">Join Our Discord</a>
</div>
</div>
</div>
</body>
</html>

<!--created by anonymous All images are copyright and belong to their respective owners,
this document is for educational purpose-->