Skip to content

Commit df87891

Browse files
authored
Merge pull request #309 from clburlison/landing-page-patches
Landing page patches
2 parents 464ce19 + 50146b1 commit df87891

File tree

6 files changed

+220
-103
lines changed

6 files changed

+220
-103
lines changed

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ app.use(async (req, res, next) => {
133133
(
134134
req.path === '/api/discord/login' ||
135135
req.path === '/login' ||
136+
req.path === '/blocked' ||
136137
(config.homePage && req.path === '/home')
137138
)
138139
) {

src/routes/discord.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,19 @@ router.get('/callback', catchAsyncErrors(async (req, res) => {
4343
req.session.username = `${user.username}#${user.discriminator}`;
4444
const perms = await DiscordClient.getPerms(user);
4545
req.session.perms = perms;
46+
const blocked = perms.blocked;
4647
const valid = perms.map !== false;
4748
req.session.valid = valid;
4849
req.session.save();
4950
if (valid) {
5051
console.log(user.id, 'Authenticated successfully.');
5152
await DiscordClient.sendMessage(config.discord.logChannelId, `${user.username}#${user.discriminator} (${user.id}) Authenticated successfully.`);
5253
res.redirect(`/?token=${response.data.access_token}`);
54+
} else if (blocked) {
55+
// User is in blocked Discord server(s)
56+
console.warn(user.id, 'Blocked due to', blocked);
57+
await DiscordClient.sendMessage(config.discord.logChannelId, `${user.username}#${user.discriminator} (${user.id}) Blocked due to ${blocked}.`);
58+
res.redirect('/blocked');
5359
} else {
5460
// Not in Discord server(s) and/or have required roles to view map
5561
console.warn(user.id, 'Not authorized to access map');

src/routes/ui.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ if (config.homePage) {
4040
});
4141
}
4242

43+
router.get('/blocked', (req, res) => {
44+
const data = {};
45+
data.discord_invite = config.discord.invite;
46+
if (req.session.username) {
47+
data.guild_name = req.session.perms.blocked;
48+
data.username = req.session.username;
49+
}
50+
res.render('blocked', data);
51+
});
52+
4353
// Location endpoints
4454
router.get('/@/:lat/:lon', async (req, res) => {
4555
res.setHeader('Content-Type', 'text/html');

src/services/discord.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DiscordClient {
3737
async getGuilds() {
3838
const guilds = await oauth.getUserGuilds(this.accessToken);
3939
const guildIds = Array.from(guilds, x => BigInt(x.id).toString());
40-
return guildIds;
40+
return [guildIds, guilds];
4141
}
4242

4343
async getUserRoles(guildId, userId) {
@@ -74,7 +74,7 @@ class DiscordClient {
7474
}
7575

7676
async getPerms(user) {
77-
const perms = {
77+
var perms = {
7878
map: false,
7979
pokemon: false,
8080
raids: false,
@@ -94,7 +94,7 @@ class DiscordClient {
9494
weather: false,
9595
devices: false
9696
};
97-
const guilds = await this.getGuilds();
97+
const [guilds, guildsFull] = await this.getGuilds();
9898
if (config.discord.allowedUsers.includes(user.id)) {
9999
Object.keys(perms).forEach((key) => perms[key] = true);
100100
console.log(`User ${user.username}#${user.discriminator} (${user.id}) in allowed users list, skipping guild and role check.`);
@@ -108,6 +108,7 @@ class DiscordClient {
108108
if (guilds.includes(guildId)) {
109109
// If so, user is not granted access
110110
blocked = true;
111+
perms["blocked"] = guildsFull.find(x => x.id === guildId).name;
111112
break;
112113
}
113114
}

src/views/blocked.mustache

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1">
5+
<style>
6+
html,
7+
body {
8+
height: 85%;
9+
width: 100%;
10+
margin: 0px;
11+
background-color: #2c2f33;
12+
background-image: url('/img/discord.png');
13+
}
14+
15+
.background {
16+
background-image:url("/img/landing.png");
17+
background-position: center;
18+
background-repeat: no-repeat;
19+
background-size: cover;
20+
height: 95%;
21+
border: 2px solid #7289da;
22+
display: block;
23+
margin-left: auto;
24+
margin-right: auto;
25+
}
26+
27+
#transbox {
28+
background-color:rgba(255,255,255,0.8);
29+
padding:20px;
30+
}
31+
32+
.title {
33+
text-align:center;
34+
font-size: 2em;
35+
color: #3C5FA3;
36+
}
37+
38+
.container {
39+
width: 90%;
40+
margin: 0 auto;
41+
padding: 30px;
42+
}
43+
44+
.clearfix:after {
45+
visibility:hidden;
46+
display:block;
47+
content:"";
48+
clear:both;
49+
height:0;
50+
}
51+
52+
.description {
53+
text-align:center;
54+
opacity: 0.5;
55+
color: #000000;
56+
margin-left: 10px;
57+
margin-bottom: 10px;
58+
white-space: pre-wrap;
59+
}
60+
61+
.make-center {
62+
text-align: center;
63+
padding: 20px 0;
64+
}
65+
66+
.square_btn{
67+
display: inline-block;
68+
padding: 7px 20px;
69+
border-radius: 25px;
70+
text-decoration: none;
71+
color: #FFF;
72+
background-image: -webkit-linear-gradient(45deg, #7289da 0%, #4d6cdb 100%);
73+
background-image: linear-gradient(45deg, #7289da 0%, #4d6cdb 100%);
74+
transition: .4s;
75+
}
76+
77+
.square_btn:hover {
78+
background-image: -webkit-linear-gradient(45deg, #7289da 0%, #3659d8 100%);
79+
background-image: linear-gradient(45deg, #7289da 0%, #3659d8 100%);
80+
}
81+
</style>
82+
</head>
83+
<body>
84+
<div class="container clearfix background">
85+
<div id="transbox">
86+
<title>Access denied</title>
87+
<div class="title">Access denied!</div>
88+
<div class="description">{{username}} has been blocked for being a member of {{guild_name}}.
89+
Please join our discord for more info.</div>
90+
<div class="make-center">
91+
<a href="/login" class="square_btn">Login</a><a href="{{discord_invite}}" class="square_btn">Join Our Discord</a>
92+
</div>
93+
</div>
94+
</div>
95+
</body>
96+
</body>
97+
</html>
98+
99+
<!--created by anonymous All images are copyright and belong to their respective owners,
100+
this document is for educational purpose-->

src/views/home.mustache

Lines changed: 99 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,99 @@
1-
<!DOCTYPE html>
2-
<html>
3-
<head>
4-
<meta name="viewport" content="width=device-width, initial-scale=1">
5-
<style>
6-
html,
7-
body {
8-
height: 80%;
9-
width: 100%;
10-
margin: 0px;
11-
background-color: #2c2f33;
12-
background-image: url('/img/discord.png');
13-
}
14-
15-
.title {
16-
font-size: 2em;
17-
color: #ffffff;
18-
margin-left: 10px;
19-
}
20-
21-
.description {
22-
opacity: 0.5;
23-
color: #ffffff;
24-
margin-left: 10px;
25-
margin-bottom: 10px;
26-
}
27-
28-
.discord-login {
29-
min-width: 7em;
30-
margin-top: 2em;
31-
margin-right: 0em;
32-
padding: 0.5em 2em;
33-
outline: none;
34-
border: 2px solid #7289da;
35-
border-radius: 8em;
36-
color: #7289da;
37-
cursor: pointer;
38-
transition-duration: 0.2s;
39-
font-size: 0.95em;
40-
font-family: 'Righteous';
41-
margin-left: 10px;
42-
}
43-
44-
.discord-login--active {
45-
background-color: #7289da;
46-
border: 2px solid #7289da;
47-
color: white;
48-
}
49-
50-
.discord-login--active:hover {
51-
box-shadow: 0px 0px 10px 1px rgba(114,137,218,1);
52-
color: #2c2f33;
53-
}
54-
55-
.discord-join {
56-
min-width: 7em;
57-
margin-top: 2em;
58-
margin-right: 0em;
59-
padding: 0.5em 2em;
60-
outline: none;
61-
border: 2px solid #7289da;
62-
background-color: transparent;
63-
border-radius: 8em;
64-
color: #7289da;
65-
cursor: pointer;
66-
transition-duration: 0.2s;
67-
font-size: 0.95em;
68-
font-family: 'Righteous';
69-
margin-left: 10px;
70-
}
71-
72-
.discord-join:hover {
73-
color: white;
74-
}
75-
76-
img {
77-
width: 98%;
78-
border: 2px solid #7289da;
79-
display: block;
80-
margin-left: auto;
81-
margin-right: auto;
82-
margin-top: 5px;
83-
margin-bottom: 3px;
84-
vertical-align: middle;
85-
}
86-
</style>
87-
</head>
88-
<body>
89-
<img src="/img/landing.png" >
90-
<div class="title">WELCOME!</div>
91-
<div class="description">The best place to find pokemon</div>
92-
<div class="description">Please login or join discord for more info</div>
93-
<a href="/login" class="discord-login discord-login--active">Login</a>
94-
<a href="{{discord_invite}}" class="discord-join">Join Our Discord</a>
95-
</div>
96-
</body>
97-
</html>
98-
99-
<!--created by anonymous All images are copyright and belong to their respective owners,
100-
this document is for educational purpose-->
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1">
5+
<style>
6+
html,
7+
body {
8+
height: 85%;
9+
width: 100%;
10+
margin: 0px;
11+
background-color: #2c2f33;
12+
background-image: url('/img/discord.png');
13+
}
14+
15+
.background {
16+
background-image:url("/img/landing.png");
17+
background-position: center;
18+
background-repeat: no-repeat;
19+
background-size: cover;
20+
height: 95%;
21+
border: 2px solid #7289da;
22+
display: block;
23+
margin-left: auto;
24+
margin-right: auto;
25+
}
26+
27+
#transbox {
28+
background-color:rgba(255,255,255,0.8);
29+
padding:20px;
30+
}
31+
32+
.title {
33+
text-align:center;
34+
font-size: 2em;
35+
color: #3C5FA3;
36+
}
37+
38+
.container {
39+
width: 90%;
40+
margin: 0 auto;
41+
padding: 30px;
42+
}
43+
44+
.clearfix:after {
45+
visibility:hidden;
46+
display:block;
47+
content:"";
48+
clear:both;
49+
height:0;
50+
}
51+
52+
.description {
53+
text-align:center;
54+
opacity: 0.5;
55+
color: #000000;
56+
margin-left: 10px;
57+
margin-bottom: 10px;
58+
white-space: pre-wrap;
59+
}
60+
61+
.make-center {
62+
text-align: center;
63+
padding: 20px 0;
64+
}
65+
66+
.square_btn{
67+
display: inline-block;
68+
padding: 7px 20px;
69+
border-radius: 25px;
70+
text-decoration: none;
71+
color: #FFF;
72+
background-image: -webkit-linear-gradient(45deg, #7289da 0%, #4d6cdb 100%);
73+
background-image: linear-gradient(45deg, #7289da 0%, #4d6cdb 100%);
74+
transition: .4s;
75+
}
76+
77+
.square_btn:hover {
78+
background-image: -webkit-linear-gradient(45deg, #7289da 0%, #3659d8 100%);
79+
background-image: linear-gradient(45deg, #7289da 0%, #3659d8 100%);
80+
}
81+
</style>
82+
</head>
83+
<body>
84+
<div class="container clearfix background">
85+
<div id="transbox">
86+
<title>Welcome</title>
87+
<div class="title">Welcome</div>
88+
<div class="description">The best place to find pokemon.</div>
89+
<div class="description">Please login or join discord for more info...</div>
90+
<div class="make-center">
91+
<a href="/login" class="square_btn">Login</a><a href="{{discord_invite}}" class="square_btn">Join Our Discord</a>
92+
</div>
93+
</div>
94+
</div>
95+
</body>
96+
</html>
97+
98+
<!--created by anonymous All images are copyright and belong to their respective owners,
99+
this document is for educational purpose-->

0 commit comments

Comments
 (0)