[O] Reject unauthenticated aimedb requests

This commit is contained in:
Azalea
2024-03-05 14:47:02 -05:00
parent 55804be70e
commit b9c063c41e
2 changed files with 23 additions and 11 deletions

View File

@@ -1,10 +1,9 @@
package icu.samnyan.aqua.net.db
import com.fasterxml.jackson.annotation.JsonIgnore
import ext.Str
import ext.async
import ext.isValidEmail
import ext.minus
import ext.*
import icu.samnyan.aqua.sega.allnet.AllNetProps
import icu.samnyan.aqua.sega.allnet.KeyChipRepo
import icu.samnyan.aqua.sega.allnet.KeychipSession
import icu.samnyan.aqua.sega.general.dao.CardRepository
import icu.samnyan.aqua.sega.general.model.Card
@@ -101,6 +100,8 @@ class AquaUserServices(
val userRepo: AquaNetUserRepo,
val cardRepo: CardRepository,
val hasher: PasswordEncoder,
val keyChipRepo: KeyChipRepo,
val allNetProps: AllNetProps
) {
companion object {
val SETTING_FIELDS = AquaUserServices::class.functions
@@ -121,6 +122,13 @@ class AquaUserServices(
?.let { callback(it) } ?: (404 - "Card not found")
else byName(username) { callback(it.ghostCard) }
fun validKeychip(keychipId: Str): Bool {
if (!allNetProps.checkKeychip) return true
if (keychipId.isBlank()) return false
if (userRepo.findByKeychip(keychipId) != null || keyChipRepo.existsByKeychipId(keychipId)) return true
return false
}
fun checkUsername(username: Str) = username.apply {
// Check if username is valid
if (length < 2) 400 - "Username must be at least 2 letters"