diff --git a/web/components/Whitelist.vue b/web/components/Whitelist.vue index 7323ca4..28b8104 100644 --- a/web/components/Whitelist.vue +++ b/web/components/Whitelist.vue @@ -34,7 +34,7 @@ const submitCode = async () => { user.value.minecraft.uuid = response.uuid user.value.minecraft.username = response.username - useToast().success('Successfully whitelisted') + useToast().success('Succesvol gewhitelist') } catch (e) { console.log(e); useToast().error(e.statusMessage) diff --git a/web/components/team/Default.vue b/web/components/team/Default.vue index 049b033..e1853ce 100644 --- a/web/components/team/Default.vue +++ b/web/components/team/Default.vue @@ -82,7 +82,7 @@ const leaveTeam = async () => { user.value.team = null; - useToast().success('Successfully left team') + useToast().success('Succesvol team verlaten') } catch (e) { console.log(e); useToast().error(e.statusMessage) @@ -102,7 +102,7 @@ const editTeam = async () => { team.value.name = editTeamModal.value.name team.value.color = editTeamModal.value.color - useToast().success('Successfully modified team') + useToast().success('Team is succesvol bewerkt') editTeamModal.value.open = false } catch (e) { @@ -120,7 +120,7 @@ const inviteUser = async (usr) => { usr.teamInvites.push(user.value.team.id); - useToast().success(`Successfully invited ${usr.username}`) + useToast().success(`Invited ${usr.username} succesvol`) } catch (e) { console.log(e); useToast().error(e.statusMessage) @@ -136,7 +136,7 @@ const cancelInvite = async (usr) => { usr.teamInvites = usr.teamInvites.filter(a => a !== user.value.team.id); - useToast().success('Successfully cancelled invited') + useToast().success('Succesvol invite geannuleerd') } catch (e) { console.log(e); useToast().error(e.statusMessage) @@ -155,7 +155,7 @@ const promoteUser = async (usr) => { console.log(usr) console.log(teamMembers) - useToast().success('Successfully promted user') + useToast().success('Succesvol gebruiker gepromoveerd') } catch (e) { console.log(e); useToast().error(e.statusMessage) @@ -171,7 +171,7 @@ const demoteUser = async (usr) => { usr.team.admin = false - useToast().success('Successfully demoted user') + useToast().success('Succesvol gebruiker gedegradeerd') } catch (e) { console.log(e); useToast().error(e.statusMessage) diff --git a/web/components/team/None.vue b/web/components/team/None.vue index 5ff7ecf..2ddafa5 100644 --- a/web/components/team/None.vue +++ b/web/components/team/None.vue @@ -55,12 +55,10 @@ const acceptInvite = async (team) => { method: 'POST', body: { teamId: team._id } }) - - console.log(response) user.value.team = { id: response._id, admin: false } - useToast().success('Successfully joined team') + useToast().success('Succesvol lid geworden van het team') } catch (e) { console.log(e); useToast().error(e.statusMessage) @@ -76,7 +74,7 @@ const handleCreateTeam = async () => { user.value.team = { id: response.insertedId.toString(), admin: true } - useToast().success('Successfully created team') + useToast().success('Succesvol team gemaakt') } catch (e) { console.log(e); diff --git a/web/pages/index.vue b/web/pages/index.vue index 49fb6d7..3dd5abe 100644 --- a/web/pages/index.vue +++ b/web/pages/index.vue @@ -63,7 +63,7 @@ const refreshMinecraftUsername = async () => { user.value.minecraft.username = response.username - useToast().success('Username is ververst') + useToast().success('Gebruikersnaam is ververst') } catch (e) { console.log(e) @@ -77,7 +77,7 @@ const refreshDiscordUsername = async () => { user.value.discord.username = response.username - useToast().success('Username is ververst') + useToast().success('Gebruikersnaam is ververst') } catch (e) { console.log(e) diff --git a/web/server/api/auth/index.js b/web/server/api/auth/index.js index d0de238..768e253 100644 --- a/web/server/api/auth/index.js +++ b/web/server/api/auth/index.js @@ -45,7 +45,7 @@ export default defineEventHandler(async (event) => { } catch (e) { console.log(e) - throw createError({ statusCode: 500, statusMessage: 'Error creating login token'}) + throw createError({ statusCode: 500, statusMessage: 'Error tijdens het genereren van JWT token'}) } return sendRedirect(event, '/', 302) diff --git a/web/server/api/auth/user/index.js b/web/server/api/auth/user/index.js index 4e006e5..87e2d66 100644 --- a/web/server/api/auth/user/index.js +++ b/web/server/api/auth/user/index.js @@ -1,5 +1,5 @@ export default defineEventHandler(async (event) => { - const auth = await getAuth(event) + const user = await getAuth(event) - return auth + return user }); diff --git a/web/server/api/auth/user/setdefaultusername.js b/web/server/api/auth/user/setdefaultusername.js index c582f8b..2624553 100644 --- a/web/server/api/auth/user/setdefaultusername.js +++ b/web/server/api/auth/user/setdefaultusername.js @@ -2,7 +2,6 @@ import { ObjectId } from "mongodb"; export default defineEventHandler(async (event) => { const { type } = await readBody(event) - const auth = await getAuth(event) const usersColl = db.collection('users') diff --git a/web/server/api/minecraft/message/chattominecraft.js b/web/server/api/minecraft/message/chattominecraft.js index 6a24da2..e9884de 100644 --- a/web/server/api/minecraft/message/chattominecraft.js +++ b/web/server/api/minecraft/message/chattominecraft.js @@ -6,5 +6,5 @@ export default defineEventHandler(async (event) => { await sendRconCommand(`tellraw @a {"text":"(DC) ${doc.discord.username} > ${content}"}`) - return { whoo: 'hi' } + return { status: 'success' } }); diff --git a/web/server/api/minecraft/message/gametodiscord.js b/web/server/api/minecraft/message/gametodiscord.js index 2e1ed15..66c1606 100644 --- a/web/server/api/minecraft/message/gametodiscord.js +++ b/web/server/api/minecraft/message/gametodiscord.js @@ -14,5 +14,5 @@ export default defineEventHandler(async (event) => { } }) - return { code: 'success' } + return { status: 'success' } }); diff --git a/web/server/api/minecraft/refreshusername.js b/web/server/api/minecraft/refreshusername.js index c1b93f5..fe49e7c 100644 --- a/web/server/api/minecraft/refreshusername.js +++ b/web/server/api/minecraft/refreshusername.js @@ -1,7 +1,7 @@ export default defineEventHandler(async (event) => { const auth = await getAuth(event) - if (!auth.minecraft.uuid) throw createError({ errorCode: 400, statusMessage: 'No Minecraft account is linked' }) + if (!auth.minecraft.uuid) throw createError({ errorCode: 400, statusMessage: 'Geen Minecraft account is gekoppeld' }) const minecraftProfile = await $fetch(`https://sessionserver.mojang.com/session/minecraft/profile/${auth.minecraft.uuid}`) diff --git a/web/server/api/minecraft/removewhitelist.js b/web/server/api/minecraft/removewhitelist.js index 29fbafa..dc274e9 100644 --- a/web/server/api/minecraft/removewhitelist.js +++ b/web/server/api/minecraft/removewhitelist.js @@ -1,7 +1,7 @@ export default defineEventHandler(async (event) => { const auth = await getAuth(event) - if (!auth.minecraft.uuid) throw createError({ errorCode: 400, statusMessage: 'No Minecraft account is linked' }) + if (!auth.minecraft.uuid) throw createError({ errorCode: 400, statusMessage: 'Geen Minecraft account is gekoppeld' }) const whitelistColl = db.collection('whitelist') await whitelistColl.deleteOne({ uuid: auth.minecraft.uuid }) diff --git a/web/server/api/minecraft/whitelist.js b/web/server/api/minecraft/whitelist.js index d6a89f0..d37541b 100644 --- a/web/server/api/minecraft/whitelist.js +++ b/web/server/api/minecraft/whitelist.js @@ -1,14 +1,14 @@ export default defineEventHandler(async (event) => { const { code } = await readBody(event) - if (!code) throw createError({ statusCode: 400, statusMessage: 'Code is required'}) + if (!code) throw createError({ statusCode: 400, statusMessage: 'Code is vereist'}) const auth = await getAuth(event) const whitelistColl = db.collection('whitelist') const whitelistDoc = await whitelistColl.findOne({ code: code.toString() }) - if (!whitelistDoc) throw createError({ statusCode: 400, statusMessage: 'Code has not been found, join the server first' }) + if (!whitelistDoc) throw createError({ statusCode: 400, statusMessage: 'Code is niet gevonden, join eerste de Minecraft server' }) if (whitelistDoc && whitelistDoc.verified) throw createError({ statusCode: 400, statusMessage: 'Already verified' }) await whitelistColl.updateOne({ code: code.toString() }, { $set: { verified: true } }) diff --git a/web/server/api/team/acceptinvite.js b/web/server/api/team/acceptinvite.js index e4c77ac..4674db0 100644 --- a/web/server/api/team/acceptinvite.js +++ b/web/server/api/team/acceptinvite.js @@ -10,7 +10,7 @@ export default defineEventHandler(async (event) => { const team = await teamsColl.findOneAndUpdate({ _id: new ObjectId(teamId) }, { $inc: { count: 1 } }) - if (!team.value) return createError({ statusCode: 500, statusMessage: 'Could not find team'}) + if (!team.value) return createError({ statusCode: 500, statusMessage: 'Team niet gevonden'}) await usersColl.updateOne({ _id: new ObjectId(user._id) }, { $set: { 'team.id': teamId, 'team.admin': false }}) diff --git a/web/server/api/team/create.post.js b/web/server/api/team/create.post.js index ea9cf26..915a2a2 100644 --- a/web/server/api/team/create.post.js +++ b/web/server/api/team/create.post.js @@ -1,17 +1,18 @@ export default defineEventHandler(async (event) => { const { teamName, teamColor } = await readBody(event); - if (!teamName || !teamColor) return createError({ statusCode: 400, statusMessage: 'teamName and teamColor are required' }) - if (!isHexColor(teamColor)) return createError({ statusCode: 400, statusMessage: 'Team color is not a valid hex code' }) + if (!teamName || !teamColor) return createError({ statusCode: 400, statusMessage: 'Team naam en kleur zijn vereist' }) + if (!isHexColor(teamColor)) return createError({ statusCode: 400, statusMessage: 'Team kleur is geen gelidige kleurencode' }) + if (!verifyUsername(teamName)) return createError({ statusCode: 400, statusMessage: 'Team naam moet alfanumeriek zijn en mag maximaal 20 tekens lang zijn' }) const user = await getAuth(event) - if (user.team) return createError({ statusCode: 400, statusMessage: 'User already is in a team' }) + if (user.team) return createError({ statusCode: 400, statusMessage: 'Gebruiker is al in een team' }) const teamsColl = db.collection('teams') const usersColl = db.collection('users') - if (await teamsColl.findOne({ name: teamName })) return createError({ statusCode: 400, statusMessage: 'Team name already exists' }) + if (await teamsColl.findOne({ name: { $regex: new RegExp(teamName, "i") } })) return createError({ statusCode: 400, statusMessage: 'Team naam bestaat al' }) const response = await teamsColl.insertOne({ name: teamName, color: teamColor, count: 1 }) diff --git a/web/server/api/team/demote.js b/web/server/api/team/demote.js index a439e77..614a260 100644 --- a/web/server/api/team/demote.js +++ b/web/server/api/team/demote.js @@ -5,7 +5,7 @@ export default defineEventHandler(async (event) => { const user = await getAuth(event) - if (!user.team.admin) return createError({ statusCode: 403, statusMessage: 'Forbidden' }) + if (!user.team.admin) return createError({ statusCode: 403, statusMessage: 'Admin team rol vereist' }) const usersColl = db.collection('users') await usersColl.findOneAndUpdate({ _id: new ObjectId(userId) }, { $set: { 'team.admin': false } }); diff --git a/web/server/api/team/edit.js b/web/server/api/team/edit.js index a5701d1..d7ef740 100644 --- a/web/server/api/team/edit.js +++ b/web/server/api/team/edit.js @@ -3,7 +3,9 @@ import { ObjectId } from 'mongodb' export default defineEventHandler(async (event) => { const { name, color } = await readBody(event); - if (!isHexColor(color)) return createError({ statusCode: 400, statusMessage: 'Team color is not a valid hex code' }) + if (!name || !color) return createError({ statusCode: 400, statusMessage: 'Team naam en kleur zijn vereist' }) + if (!isHexColor(color)) return createError({ statusCode: 400, statusMessage: 'Team kleur is geen goede kleurencode' }) + if (!verifyUsername(name)) return createError({ statusCode: 400, statusMessage: 'Team naam moet alfanumeriek zijn en mag maximaal 20 tekens lang zijn' }) const user = await getAuth(event) @@ -11,7 +13,7 @@ export default defineEventHandler(async (event) => { const team = await teamsColl.findOne({ _id: new ObjectId(user.team.id) }); - if (team.name !== name && await teamsColl.findOne({ name: name })) return createError({ statusCode: 400, statusMessage: 'Team name already exists' }) + if (team.name !== name && await teamsColl.findOne({ name: { $regex: new RegExp(name, "i") } })) return createError({ statusCode: 400, statusMessage: 'Team naam bestaat al' }) await teamsColl.updateOne({ _id: new ObjectId(user.team.id) }, { $set: { name: name, color: color } }) diff --git a/web/server/api/team/invite.js b/web/server/api/team/invite.js index 80d6d2c..f592661 100644 --- a/web/server/api/team/invite.js +++ b/web/server/api/team/invite.js @@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => { const invitedUser = await usersColl.findOne({ _id: new ObjectId(id)}); - if (invitedUser.team) return createError({ statusCode: 400, statusMessage: 'User already is in a team' }) + if (invitedUser.team) return createError({ statusCode: 400, statusMessage: 'Gebruiker zit al in een team' }) usersColl.updateOne({ _id: new ObjectId(id) }, { $push: { teamInvites: team._id.toString() } }) diff --git a/web/server/api/team/members.js b/web/server/api/team/members.js index 96db79e..0dea1f7 100644 --- a/web/server/api/team/members.js +++ b/web/server/api/team/members.js @@ -5,7 +5,7 @@ export default defineEventHandler(async (event) => { const cursor = usersColl.find({ 'team.id': user.team.id }) if((await usersColl.countDocuments({ 'team.id': user.team.id })) === 0) { - return createError({ statusCode: 500, statusMessage: 'No users were found' }) + return createError({ statusCode: 500, statusMessage: 'Geen gebruikers zijn gevonden' }) } const users = []; diff --git a/web/server/api/team/promote.js b/web/server/api/team/promote.js index fa3a4eb..c9b4ae7 100644 --- a/web/server/api/team/promote.js +++ b/web/server/api/team/promote.js @@ -5,7 +5,7 @@ export default defineEventHandler(async (event) => { const user = await getAuth(event) - if (!user.team.admin) return createError({ statusCode: 403, statusMessage: 'Forbidden' }) + if (!user.team.admin) return createError({ statusCode: 403, statusMessage: 'Admin team rol is vereist' }) const usersColl = db.collection('users') await usersColl.findOneAndUpdate({ _id: new ObjectId(userId) },{ $set: { 'team.admin': true } }); diff --git a/web/server/api/team/unaffiliated.js b/web/server/api/team/unaffiliated.js index 631b71e..9f64199 100644 --- a/web/server/api/team/unaffiliated.js +++ b/web/server/api/team/unaffiliated.js @@ -1,4 +1,4 @@ -export default defineEventHandler(async (event) => { +export default defineEventHandler(async () => { const usersColl = db.collection('users') const cursor = usersColl.find({ team: { $exists: false } }) const unaffiliatedUsers = await cursor.toArray() diff --git a/web/server/utils/auth.js b/web/server/utils/auth.js index 5b4efa2..3fc2d00 100644 --- a/web/server/utils/auth.js +++ b/web/server/utils/auth.js @@ -14,7 +14,7 @@ export const getAuth = async (event) => { if (!token) { throw createError({ statusCode: 401, - statusMessage: 'JWT token invalid', + statusMessage: 'JWT token is niet geldig', }) } @@ -28,7 +28,7 @@ export const getAuth = async (event) => { throw createError({ statusCode: 401, - statusMessage: 'JWT token invalid', + statusMessage: 'JWT token is niet geldig', }) } @@ -44,7 +44,7 @@ export const getAuth = async (event) => { throw createError({ statusCode: 500, - statusMessage: 'Error getting user' + statusMessage: 'Error tijdens ophalen van gegevens' }) } } diff --git a/web/server/utils/check.js b/web/server/utils/check.js index 545dc05..4cf27e3 100644 --- a/web/server/utils/check.js +++ b/web/server/utils/check.js @@ -2,3 +2,14 @@ export const isHexColor = (str) => { const pattern = /^#([0-9A-F]{3}){1,2}$/i; return pattern.test(str); } + +export const verifyUsername = (username) => { + const alphanumeric = /^[a-zA-Z0-9]+$/; + if (username.length > 20) { + return false; + } + if (!alphanumeric.test(username)) { + return false; + } + return true; +}