added whitelist system
This commit is contained in:
parent
cafa230433
commit
99c7ef381d
@ -1,12 +1,31 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="w-full h-full text-primary flex pt-20 items-center flex-col">
|
<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>
|
<h1 class="sm:text-4xl text-2xl font-bold text-center mb-10">Whitelist</h1>
|
||||||
<p v-if="!user.minecraft.uuid" class="max-w-xl mb-10 sm:text-base text-sm">
|
<div v-if="!user.minecraft.uuid" class="flex flex-col items-center">
|
||||||
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 class="max-w-xl mb-10 sm:text-base text-sm">
|
||||||
</p>
|
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.
|
||||||
<div class="flex gap-2">
|
</p>
|
||||||
<Input v-model:value="code">Code</Input>
|
<div class="flex gap-2">
|
||||||
<Button @click="submitCode">Submit</Button>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -19,6 +38,34 @@ definePageMeta({
|
|||||||
const user = useState('user')
|
const user = useState('user')
|
||||||
const code = ref('')
|
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 () => {
|
const submitCode = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await $fetch('/api/minecraft/whitelist', {
|
const response = await $fetch('/api/minecraft/whitelist', {
|
||||||
@ -29,6 +76,8 @@ const submitCode = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
user.value.minecraft.uuid = response.uuid
|
user.value.minecraft.uuid = response.uuid
|
||||||
|
user.value.minecraft.username = response.username
|
||||||
|
|
||||||
useToast().success('Successfully whitelisted')
|
useToast().success('Successfully whitelisted')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(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) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const auth = getAuth(event)
|
|
||||||
|
|
||||||
const { uuid } = await readBody(event)
|
const { uuid } = await readBody(event)
|
||||||
|
|
||||||
const coll = db.collection('whitelist')
|
const coll = db.collection('whitelist')
|
||||||
|
@ -3,7 +3,6 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
if (!code) throw createError({ statusCode: 400, statusMessage: 'Code is required'})
|
if (!code) throw createError({ statusCode: 400, statusMessage: 'Code is required'})
|
||||||
|
|
||||||
const config = useRuntimeConfig()
|
|
||||||
const auth = await getAuth(event)
|
const auth = await getAuth(event)
|
||||||
|
|
||||||
const whitelistColl = db.collection('whitelist')
|
const whitelistColl = db.collection('whitelist')
|
||||||
@ -14,9 +13,11 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
await whitelistColl.updateOne({ code: code.toString() }, { $set: { verified: true } })
|
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')
|
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