pineafan | 513c0a2 | 2021-09-04 09:54:42 +0100 | [diff] [blame] | 1 | import { MongoClient } from 'mongodb'; |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 2 | |
| 3 | |
| 4 | const url = 'mongodb://rsm:LJMy*orVFAATQ5PaX7EKXq74&HCDFaLE@192.168.101.2:27017/rsm'; |
| 5 | const db = 'rsm'; |
| 6 | const collection = 'rsmv-tokens' |
| 7 | |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 8 | const Validate = (req, res) => { |
pineafan | 98f4297 | 2021-09-04 10:01:56 +0100 | [diff] [blame] | 9 | console.log("A") |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 10 | 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}); |
pineafan | 98f4297 | 2021-09-04 10:01:56 +0100 | [diff] [blame] | 13 | |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 14 | if (!db_response) return resolve(res.status(404).end()); |
| 15 | if (db_response.timestamp + (1800) >= Date.now()) return resolve(res.status(410)); |
pineafan | 98f4297 | 2021-09-04 10:01:56 +0100 | [diff] [blame] | 16 | |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 17 | 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 | } |
pineafan | 98f4297 | 2021-09-04 10:01:56 +0100 | [diff] [blame] | 26 | console.log("B") |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 27 | return resolve(res.status(200).send(props)); |
| 28 | }) |
| 29 | }) |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | export default Validate; |