forked from Cookies_Github_mirror/AquaDX
[+] Add change name for maimai and refactor settings page
This commit is contained in:
@@ -23,6 +23,18 @@ fun usernameCheck(chars: String): (IUserData, String) -> Unit = { u, v ->
|
||||
v.find { it !in chars }?.let { 400 - "Invalid character '$it' in username" }
|
||||
}
|
||||
|
||||
fun toFullWidth(input: String): String {
|
||||
val stringBuilder = StringBuilder()
|
||||
for (char in input.toCharArray()) {
|
||||
if (char.code in 33..126) {
|
||||
stringBuilder.append((char.code + 65248).toChar())
|
||||
} else {
|
||||
stringBuilder.append(char)
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
data class TrendLog(val date: String, val rating: Int)
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@ import icu.samnyan.aqua.net.games.*
|
||||
import icu.samnyan.aqua.net.utils.*
|
||||
import icu.samnyan.aqua.sega.maimai2.model.*
|
||||
import icu.samnyan.aqua.sega.maimai2.model.userdata.*
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import java.util.*
|
||||
|
||||
@@ -39,4 +40,15 @@ class Maimai2(
|
||||
|
||||
genericUserSummary(card, ratingComposition)
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("change-name")
|
||||
suspend fun changeName(@RP token: String, @RP newName: String) = us.jwt.auth(token) { u ->
|
||||
val newNameFull = toFullWidth(newName)
|
||||
us.cardByName(u.username) { card ->
|
||||
val user = userDataRepo.findByCard(card) ?: (404 - "User not found")
|
||||
settableFields["userName"]?.invoke(user, newNameFull)
|
||||
userDataRepo.save(user)
|
||||
}
|
||||
mapOf("newName" to newNameFull)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user