This repository has been archived by the owner on May 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (40 loc) · 1.6 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const axios = require('axios');
const pool = require('./pool');
const discord = require('./discord');
const {
recaptcha_secret_key
} = require('./variables');
const port = 8080;
const app = express();
app.use(express.static(path.join(__dirname, '/assets')))
app.use(bodyParser.urlencoded({
extended: true
}));
app.get('/verify/:verifyId?', (req, res) => {
if (!req.params.verifyId) return res.sendFile(path.join(__dirname, '/html/invalidLink.html'));
if (!pool.isValidLink(req.params.verifyId)) return res.sendFile(path.join(__dirname, '/html/invalidLink.html'));
res.sendFile(path.join(__dirname, '/html/verify.html'));
})
app.post('/verify/:verifyId?', async (req, res) => {
const response = await axios({
method: 'post',
url: `https://www.google.com/recaptcha/api/siteverify?secret=${recaptcha_secret_key}&response=${req.body['g-recaptcha-response']}`,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
if (!response.data.success) return res.sendFile(path.join(__dirname, '/html/invalidCaptcha.html'));
if (!pool.isValidLink(req.params.verifyId)) return res.sendFile(path.join(__dirname, '/html/invalidLink.html'));
discord.addRole(pool.getDiscordId(req.params.verifyId));
pool.removeLink(req.params.verifyId);
res.sendFile(path.join(__dirname, '/html/valid.html'));
})
function main() {
app.listen(port, () => console.log(`[Express] Listening on port ${port}.`));
}
module.exports = {
run: main
};