added whitelist system
This commit is contained in:
parent
cafa230433
commit
99c7ef381d
@ -1,12 +1,31 @@
|
||||
<template>
|
||||
<div class="w-full h-full text-primary flex pt-20 items-center flex-col">
|
||||
<h1 class="sm:text-4xl text-2xl font-bold text-center mb-5">Whitelist</h1>
|
||||
<p v-if="!user.minecraft.uuid" class="max-w-xl mb-10 sm:text-base text-sm">
|
||||
Je bent momenteel niet gewhitelist. Om toegang te krijgen tot de Minecraft server moet je in Minecraft naar de server met het ip <span class="highlight">play.polarcraft.xeovalyte.com</span> gaan. Vervolgens krijg je een code te zien, vul deze code hieronder in.
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<Input v-model:value="code">Code</Input>
|
||||
<Button @click="submitCode">Submit</Button>
|
||||
<h1 class="sm:text-4xl text-2xl font-bold text-center mb-10">Whitelist</h1>
|
||||
<div v-if="!user.minecraft.uuid" class="flex flex-col items-center">
|
||||
<p class="max-w-xl mb-10 sm:text-base text-sm">
|
||||
Je bent momenteel niet gewhitelist. Om toegang te krijgen tot de Minecraft server moet je in Minecraft naar de server met het ip <span class="highlight">play.polarcraft.xeovalyte.com</span> gaan. Vervolgens krijg je een code te zien, vul deze code hieronder in.
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<Input v-model:value="code">Code</Input>
|
||||
<Button @click="submitCode">Submit</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="flex justify-center gap-4 flex-wrap max-w-3xl w-full">
|
||||
<img :src="'https://api.mineatar.io/face/' + user.minecraft.uuid + '?scale=16'" class="w-24 rounded shadow">
|
||||
<div class="rounded flex border-2 border-primary p-4 w-full max-w-md">
|
||||
<ul class="my-auto">
|
||||
<li>Username: <b>{{ user.minecraft.username }}</b></li>
|
||||
<li>UUID: <b>{{ user.minecraft.uuid }}</b></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="w-full flex justify-center gap-4 mt-2">
|
||||
<Button type="danger" @click="removeWhitelist">
|
||||
Remove from whitelist
|
||||
</Button>
|
||||
<Button @click="refreshUsername">
|
||||
Refresh Username
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@ -19,6 +38,34 @@ definePageMeta({
|
||||
const user = useState('user')
|
||||
const code = ref('')
|
||||
|
||||
const refreshUsername = async () => {
|
||||
try {
|
||||
const response = await $fetch('/api/minecraft/refreshusername')
|
||||
|
||||
user.value.minecraft.username = response.username
|
||||
|
||||
useToast().success('Username is ververst')
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
||||
useToast().error(e.statusMessage)
|
||||
}
|
||||
}
|
||||
|
||||
const removeWhitelist = async () => {
|
||||
try {
|
||||
await $fetch('/api/minecraft/removewhitelist')
|
||||
|
||||
user.value.minecraft.uuid = null
|
||||
user.value.minecraft.username = null
|
||||
|
||||
useToast().success('Minecraft is niet meer gekoppeld')
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
useToast().error(e.statusMessage)
|
||||
}
|
||||
}
|
||||
|
||||
const submitCode = async () => {
|
||||
try {
|
||||
const response = await $fetch('/api/minecraft/whitelist', {
|
||||
@ -29,6 +76,8 @@ const submitCode = async () => {
|
||||
})
|
||||
|
||||
user.value.minecraft.uuid = response.uuid
|
||||
user.value.minecraft.username = response.username
|
||||
|
||||
useToast().success('Successfully whitelisted')
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
12
web/server/api/minecraft/refreshusername.js
Normal file
12
web/server/api/minecraft/refreshusername.js
Normal file
@ -0,0 +1,12 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const auth = await getAuth(event)
|
||||
|
||||
if (!auth.minecraft.uuid) throw createError({ errorCode: 400, statusMessage: 'No Minecraft account is linked' })
|
||||
|
||||
const minecraftProfile = await $fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${auth.minecraft.uuid}`)
|
||||
|
||||
const usersColl = db.collection('users')
|
||||
await usersColl.findOneAndUpdate({ 'minecraft.uuid': auth.minecraft.uuid }, { $set: { 'minecraft.username': minecraftProfile.name } })
|
||||
|
||||
return { username: minecraftProfile.name }
|
||||
});
|
13
web/server/api/minecraft/removewhitelist.js
Normal file
13
web/server/api/minecraft/removewhitelist.js
Normal file
@ -0,0 +1,13 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const auth = await getAuth(event)
|
||||
|
||||
if (!auth.minecraft.uuid) throw createError({ errorCode: 400, statusMessage: 'No Minecraft account is linked' })
|
||||
|
||||
const whitelistColl = db.collection('whitelist')
|
||||
await whitelistColl.deleteOne({ uuid: auth.minecraft.uuid })
|
||||
|
||||
const usersColl = db.collection('users')
|
||||
await usersColl.findOneAndUpdate({ 'minecraft.uuid': auth.minecraft.uuid }, { $set: { 'minecraft.uuid': null, 'minecraft.username': null } })
|
||||
|
||||
return { code: 'success' }
|
||||
});
|
@ -1,6 +1,4 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const auth = getAuth(event)
|
||||
|
||||
const { uuid } = await readBody(event)
|
||||
|
||||
const coll = db.collection('whitelist')
|
||||
|
@ -3,7 +3,6 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
if (!code) throw createError({ statusCode: 400, statusMessage: 'Code is required'})
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const auth = await getAuth(event)
|
||||
|
||||
const whitelistColl = db.collection('whitelist')
|
||||
@ -14,9 +13,11 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
await whitelistColl.updateOne({ code: code.toString() }, { $set: { verified: true } })
|
||||
|
||||
const minecraftProfile = await $fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${whitelistDoc.uuid}`)
|
||||
|
||||
const usersColl = db.collection('users')
|
||||
await usersColl.updateOne({ 'discord.id': auth.discord.id }, { $set: { 'minecraft.uuid': whitelistDoc.uuid } })
|
||||
await usersColl.updateOne({ 'discord.id': auth.discord.id }, { $set: { 'minecraft.uuid': whitelistDoc.uuid, 'minecraft.username': minecraftProfile.name } })
|
||||
|
||||
|
||||
return { uuid: whitelistDoc.uuid, verified: false }
|
||||
return { uuid: whitelistDoc.uuid, verified: false, username: minecraftProfile.name }
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user