diff --git a/src/main/java/icu/samnyan/aqua/net/CardController.kt b/src/main/java/icu/samnyan/aqua/net/CardController.kt index 73d7c04e..618965c7 100644 --- a/src/main/java/icu/samnyan/aqua/net/CardController.kt +++ b/src/main/java/icu/samnyan/aqua/net/CardController.kt @@ -74,6 +74,21 @@ class CardController( SUCCESS } + + @API("/unlink") + suspend fun unlink(@RP token: Str, @RP cardId: Str) = jwt.auth(token) { u -> + // Try to look up the card + val card = cardService.tryLookup(cardId) ?: (404 - "Card not found") + + // If the card is not bound to the user + if (card.aquaUser != u) 400 - "Card not bound to user" + + // Unbind the card + card.aquaUser = null + async { cardRepository.save(card) } + + SUCCESS + } } @Service