Handle invalid Minecraft UUIDs

This commit is contained in:
SKBotNL committed 2026-05-22 16:06:41 +02:00
1 parent 6059b9654f
commit 6f825e55da
3 files changed
+9 -1

No files matched your search

@@ -11,6 +11,7 @@ import net.trueog.staffauth.dto.admin.UpdateUserDto
import net.trueog.staffauth.dto.admin.UserDto
import net.trueog.staffauth.exception.user.ChangeOwnRoleException
import net.trueog.staffauth.exception.user.DeactivateSelfException
import net.trueog.staffauth.exception.user.InvalidMinecraftUuidException
import net.trueog.staffauth.service.UserService
@Controller("/user")
@@ -38,6 +39,9 @@ class UserController(private val userService: UserService) {
suspend fun delete(@PathVariable id: Long): HttpResponse<Unit> =
if (userService.delete(id) > 0) HttpResponse.noContent() else HttpResponse.notFound()
@Error(exception = InvalidMinecraftUuidException::class)
fun onInvalidMinecraftUuid(): HttpResponse<String> = HttpResponse.badRequest("INVALID_MINECRAFT_UUID")
@Error(exception = DeactivateSelfException::class)
fun onDeactivateSelf(): HttpResponse<String> = HttpResponse.badRequest("DEACTIVATE_SELF")
@@ -0,0 +1,3 @@
package net.trueog.staffauth.exception.user
class InvalidMinecraftUuidException : RuntimeException()
@@ -10,6 +10,7 @@ import net.trueog.staffauth.dto.admin.UserDto
import net.trueog.staffauth.exception.user.ChangeOwnRoleException
import net.trueog.staffauth.exception.user.DeactivateSelfException
import net.trueog.staffauth.exception.user.DuplicateMinecraftUuidException
import net.trueog.staffauth.exception.user.InvalidMinecraftUuidException
import net.trueog.staffauth.repository.UserRepository
@Singleton
@@ -43,6 +44,7 @@ class UserService(private val userRepository: UserRepository, private val minecr
throw ChangeOwnRoleException()
}
val username = minecraftClient.getByUuid(updateUserDto.minecraftUuid ?: user.minecraftUuid)?.name ?: throw InvalidMinecraftUuidException()
val updatedUser = userRepository.update(
user.copy(
email = updateUserDto.email ?: user.email,
@@ -51,7 +53,6 @@ class UserService(private val userRepository: UserRepository, private val minecr
deactivated = updateUserDto.deactivated ?: user.deactivated
)
)
val username = minecraftClient.getByUuid(updatedUser.minecraftUuid)?.name ?: throw IllegalStateException()
return UserDto.fromEntity(updatedUser, username)
}