Automatic minecraft username forward to donate page

This commit is contained in:
Evert Prants 2018-02-09 14:27:29 +02:00
parent c0a9ff5959
commit 60e9b00a74
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
4 changed files with 44 additions and 19 deletions

View File

@ -4,6 +4,14 @@ import API from './index'
import Model from './models' import Model from './models'
const mAPI = { 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) { getToken: async function (user) {
user = await API.User.ensureObject(user) user = await API.User.ensureObject(user)

View File

@ -9,6 +9,7 @@ import wrap from '../../scripts/asyncRoute'
import http from '../../scripts/http' import http from '../../scripts/http'
import API from '../api' import API from '../api'
import News from '../api/news' import News from '../api/news'
import Minecraft from '../api/minecraft'
import emailer from '../api/emailer' import emailer from '../api/emailer'
import apiRouter from './api' 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) => { router.get('/donate', wrap(async (req, res, next) => {
if (!config.donations || !config.donations.business) return 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)
})) }))
/* /*

View File

@ -29,10 +29,18 @@ block body
option(value="EUR") EUR option(value="EUR") EUR
option(value="USD") USD option(value="USD") USD
if user if user
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) input#custominfo(type="hidden", name="custom", value="userid:" + user.id)
else else
input#custominfo(type="hidden", name="custom", value="") input#custominfo(type="hidden", name="custom", value="")
if minecraft if minecraft
if minecraftName
p Donation will also be forwarded to the Minecraft server as
b= minecraftName
| .
else
.form-check.form-check-inline .form-check.form-check-inline
input.form-check-input(id="mcinclude" type="checkbox" checked="false") input.form-check-input(id="mcinclude" type="checkbox" checked="false")
label.form-check-label(for="mcinclude") Include Minecraft Username label.form-check-label(for="mcinclude") Include Minecraft Username

View File

@ -3,9 +3,7 @@ block title
|Icy Network - Minecraft Server |Icy Network - Minecraft Server
block body block body
.wrapper .container
.boxcont
.box#totpcheck
h1 Minecraft Server h1 Minecraft Server
p Link your Icy Network account with your Minecraft account on our server p Link your Icy Network account with your Minecraft account on our server
if token if token