blob: 01334055e8b3803bdfb85c66bd78724b5bcfc1dc [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) => {
pineafanc540da92021-09-03 20:33:36 +01009 return new Promise((resolve, reject) => {
10 MongoClient.connect(url, async function(err, client) {
11 let db_response = await client.db(db).collection(collection).findOne({code: req.body.code});
pineafanf97734b2021-11-23 21:11:00 +000012
pineafanc540da92021-09-03 20:33:36 +010013 if (!db_response) return resolve(res.status(404).end());
14 if (db_response.timestamp + (1800) >= Date.now()) return resolve(res.status(410));
pineafanf97734b2021-11-23 21:11:00 +000015
pineafanc540da92021-09-03 20:33:36 +010016 let props = {
17 user: db_response.user,
18 role: db_response.role,
19 role_name: db_response.role_name,
20 guild: db_response.guild,
21 guild_name: db_response.guild_name,
22 guild_icon_url: db_response.guild_icon_url,
23 guild_size: db_response.guild_size
24 }
25 return resolve(res.status(200).send(props));
26 })
27 })
pineafanaed30242021-09-04 09:33:40 +010028}
29
30export default Validate;