From 60e9b00a74d2a893f52d1d2e13829dc4ac508a18 Mon Sep 17 00:00:00 2001 From: Evert Date: Fri, 9 Feb 2018 14:27:29 +0200 Subject: [PATCH] Automatic minecraft username forward to donate page --- server/api/minecraft.js | 8 ++++++++ server/routes/index.js | 13 ++++++++++++- views/donate.pug | 22 +++++++++++++++------- views/minecraft/index.pug | 20 +++++++++----------- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/server/api/minecraft.js b/server/api/minecraft.js index e7c6936..12f0bc4 100644 --- a/server/api/minecraft.js +++ b/server/api/minecraft.js @@ -4,6 +4,14 @@ import API from './index' import Model from './models' const mAPI = { + getMinecraftUsername: async function (user) { + user = await API.User.ensureObject(user) + + let verified = await Model.MinecraftMember.query().where('user_id', user.id) + if (verified.length) return verified[0].name + + return null + }, getToken: async function (user) { user = await API.User.ensureObject(user) diff --git a/server/routes/index.js b/server/routes/index.js index 0fd035e..e481f20 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -9,6 +9,7 @@ import wrap from '../../scripts/asyncRoute' import http from '../../scripts/http' import API from '../api' import News from '../api/news' +import Minecraft from '../api/minecraft' import emailer from '../api/emailer' import apiRouter from './api' @@ -282,7 +283,17 @@ router.get('/user/manage/email', ensureLogin, wrap(async (req, res) => { router.get('/donate', wrap(async (req, res, next) => { if (!config.donations || !config.donations.business) return next() - res.render('donate', config.donations) + let mcu = null + + if (config.donations.minecraft && req.session.user) { + mcu = await Minecraft.getMinecraftUsername(req.session.user) + } + + let cfg = Object.assign({ + minecraftName: mcu + }, config.donations) + + res.render('donate', cfg) })) /* diff --git a/views/donate.pug b/views/donate.pug index c96d9ac..6d3874d 100644 --- a/views/donate.pug +++ b/views/donate.pug @@ -29,16 +29,24 @@ block body option(value="EUR") EUR option(value="USD") USD if user - input#custominfo(type="hidden", name="custom", value="userid:" + user.id) + if minecraftName + input#custominfo(type="hidden", name="custom", value="userid:" + user.id + ",mcu:" + minecraftName) + else + input#custominfo(type="hidden", name="custom", value="userid:" + user.id) else input#custominfo(type="hidden", name="custom", value="") if minecraft - .form-check.form-check-inline - input.form-check-input(id="mcinclude" type="checkbox" checked="false") - label.form-check-label(for="mcinclude") Include Minecraft Username - .mcuname.form-group(style="display: none;") - label(for="mcusername") Minecraft Username - input.form-control(id="mcusername", autocomplete="off") + if minecraftName + p Donation will also be forwarded to the Minecraft server as + b= minecraftName + | . + else + .form-check.form-check-inline + input.form-check-input(id="mcinclude" type="checkbox" checked="false") + label.form-check-label(for="mcinclude") Include Minecraft Username + .mcuname.form-group(style="display: none;") + label(for="mcusername") Minecraft Username + input.form-control(id="mcusername", autocomplete="off") .buttoncont a.btn.btn-primary.text-light(name="submit", onclick="$(this).closest('form').submit()") i.fa.fa-fw.fa-paypal diff --git a/views/minecraft/index.pug b/views/minecraft/index.pug index c0d75f6..1050833 100644 --- a/views/minecraft/index.pug +++ b/views/minecraft/index.pug @@ -3,15 +3,13 @@ block title |Icy Network - Minecraft Server block body - .wrapper - .boxcont - .box#totpcheck - h1 Minecraft Server - p Link your Icy Network account with your Minecraft account on our server - if token - p Run the following command on the Minecraft Server: - code /verify #{token} - else - p You've already logged in as - b= mcu.name + .container + h1 Minecraft Server + p Link your Icy Network account with your Minecraft account on our server + if token + p Run the following command on the Minecraft Server: + code /verify #{token} + else + p You've already logged in as + b= mcu.name