[+] Link card limit on the backend

pull/14/head
Azalea 2024-02-22 10:51:22 -05:00
parent a128546954
commit 0937915839
3 changed files with 19 additions and 0 deletions

View File

@ -87,6 +87,9 @@ spring.datasource.url=jdbc:sqlite:data/db.sqlite
## AquaNet Settings ## AquaNet Settings
################################ ################################
## Link card limit
aqua-net.link-card-limit=10
## CloudFlare Turnstile Captcha ## CloudFlare Turnstile Captcha
## This enables captcha for user registration. ## This enables captcha for user registration.
aqua-net.turnstile.enable=false aqua-net.turnstile.enable=false

View File

@ -2,6 +2,7 @@ package icu.samnyan.aqua.net
import ext.* import ext.*
import icu.samnyan.aqua.net.components.JWT import icu.samnyan.aqua.net.components.JWT
import icu.samnyan.aqua.net.utils.AquaNetProps
import icu.samnyan.aqua.net.utils.SUCCESS import icu.samnyan.aqua.net.utils.SUCCESS
import icu.samnyan.aqua.sega.general.dao.CardRepository import icu.samnyan.aqua.sega.general.dao.CardRepository
import icu.samnyan.aqua.sega.general.model.Card import icu.samnyan.aqua.sega.general.model.Card
@ -17,10 +18,12 @@ class CardController(
val cardService: CardService, val cardService: CardService,
val cardGameService: CardGameService, val cardGameService: CardGameService,
val cardRepository: CardRepository, val cardRepository: CardRepository,
val props: AquaNetProps
) { ) {
@API("/summary") @API("/summary")
suspend fun summary(@RP cardId: Str): Any suspend fun summary(@RP cardId: Str): Any
{ {
// DO NOT CHANGE THIS ERROR MESSAGE - The frontend uses it to detect if the card is not found
val card = cardService.tryLookup(cardId) ?: (404 - "Card not found") val card = cardService.tryLookup(cardId) ?: (404 - "Card not found")
// Lookup data for each game // Lookup data for each game
@ -41,6 +44,9 @@ class CardController(
*/ */
@API("/bind") @API("/bind")
suspend fun bind(@RP token: Str, @RP cardId: Str, @RP migrate: Str) = jwt.auth(token) { u -> suspend fun bind(@RP token: Str, @RP cardId: Str, @RP migrate: Str) = jwt.auth(token) { u ->
// Check if the user's card limit is reached
if (u.cards.size >= props.linkCardLimit) 400 - "Card limit reached"
// Check if the card is already bound // Check if the card is already bound
val card = cardService.tryLookup(cardId) ?: (404 - "Card not found") val card = cardService.tryLookup(cardId) ?: (404 - "Card not found")
if (card.aquaUser != null) 400 - "Card already bound to another user (@${card.aquaUser?.username})" if (card.aquaUser != null) 400 - "Card already bound to another user (@${card.aquaUser?.username})"

View File

@ -0,0 +1,10 @@
package icu.samnyan.aqua.net.utils
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
@Configuration
@ConfigurationProperties(prefix = "aqua-net")
class AquaNetProps {
var linkCardLimit: Int = 10
}