added whitelist system
This commit is contained in:
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 }
|
||||
});
|
||||
|
Reference in New Issue
Block a user