From fc78d3fdeac16761c6af7ba500c38a06b058b16b Mon Sep 17 00:00:00 2001 From: Evert Date: Tue, 3 Oct 2017 14:21:15 +0300 Subject: [PATCH] goddamn it forgot this --- server/routes/index.js | 2 ++ server/routes/minecraft.js | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 server/routes/minecraft.js diff --git a/server/routes/index.js b/server/routes/index.js index ac23f31..847f100 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -13,6 +13,7 @@ import emailer from '../api/emailer' import apiRouter from './api' import oauthRouter from './oauth2' import adminRouter from './admin' +import mcRouter from './minecraft' let router = express.Router() @@ -739,6 +740,7 @@ router.get('/activate/:token', wrap(async (req, res) => { router.use('/api', apiRouter) router.use('/admin', adminRouter) +router.use('/mc', mcRouter) /* NO ROUTES BEYOND THIS POINT diff --git a/server/routes/minecraft.js b/server/routes/minecraft.js new file mode 100644 index 0000000..9b08998 --- /dev/null +++ b/server/routes/minecraft.js @@ -0,0 +1,27 @@ +import express from 'express' +import wrap from '../../scripts/asyncRoute' +import Minecraft from '../api/minecraft' + +let router = express.Router() + +router.get('/', wrap(async (req, res) => { + if (!req.session.user) { + req.session.redirectUri = req.originalUrl + return res.redirect('/login') + } + + let token = await Minecraft.getToken(req.session.user) + + res.render('minecraft/index', {token: token.token, mcu: token.mcu}) +})) + +router.post('/verify/', wrap(async (req, res) => { + if (!req.body.name || !req.body.uuid || !req.body.token) return res.status(400).jsonp({error: 'Missing field.'}) + + let verify = await Minecraft.verifyToken(req.body.token, req.body.name, req.body.uuid) + if (!verify) return res.status(400).jsonp({error: 'Already verified.'}) + + res.status(200).end() +})) + +module.exports = router