blob: ae42c556f26c78866ee8815c2a115a4610af32b6 [file] [log] [blame]
pineafan513c0a22021-09-04 09:54:42 +01001import { MongoClient } from 'mongodb';
pineafanc540da92021-09-03 20:33:36 +01002
3
4const url = 'mongodb://rsm:LJMy*orVFAATQ5PaX7EKXq74&HCDFaLE@192.168.101.2:27017/rsm';
5const db = 'rsm';
6const collection = 'rsmv-tokens'
7
pineafanaed30242021-09-04 09:33:40 +01008const Validate = (req, res) => {
pineafan98f42972021-09-04 10:01:56 +01009 console.log("A")
pineafanc540da92021-09-03 20:33:36 +010010 return new Promise((resolve, reject) => {
11 MongoClient.connect(url, async function(err, client) {
12 let db_response = await client.db(db).collection(collection).findOne({code: req.body.code});
pineafan98f42972021-09-04 10:01:56 +010013
pineafanc540da92021-09-03 20:33:36 +010014 if (!db_response) return resolve(res.status(404).end());
15 if (db_response.timestamp + (1800) >= Date.now()) return resolve(res.status(410));
pineafan98f42972021-09-04 10:01:56 +010016
pineafanc540da92021-09-03 20:33:36 +010017 let props = {
18 user: db_response.user,
19 role: db_response.role,
20 role_name: db_response.role_name,
21 guild: db_response.guild,
22 guild_name: db_response.guild_name,
23 guild_icon_url: db_response.guild_icon_url,
24 guild_size: db_response.guild_size
25 }
pineafan98f42972021-09-04 10:01:56 +010026 console.log("B")
pineafanc540da92021-09-03 20:33:36 +010027 return resolve(res.status(200).send(props));
28 })
29 })
pineafanaed30242021-09-04 09:33:40 +010030}
31
32export default Validate;