mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-08 11:27:26 +08:00
[+] Keychip endpoint
This commit is contained in:
@@ -166,4 +166,19 @@ class UserRegistrar(
|
|||||||
|
|
||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val keychipRange = 1e9.toULong()..1e10.toULong() - 1UL
|
||||||
|
|
||||||
|
@API("/keychip")
|
||||||
|
@Doc("Get a Keychip ID so that the user can connect to the server.", "Success message")
|
||||||
|
suspend fun setupConnection(@RP token: Str) = jwt.auth(token) { u ->
|
||||||
|
if (u.keychip != null) mapOf("keychip" to u.keychip)
|
||||||
|
|
||||||
|
// Generate a keychip id with 10 digits (e.g. A1234567890)
|
||||||
|
var new = "A" + keychipRange.random()
|
||||||
|
while (async { userRepo.findByKeychip(new) != null }) new = "A" + keychipRange.random()
|
||||||
|
async { userRepo.save(u.apply { keychip = new }) }
|
||||||
|
|
||||||
|
mapOf("keychip" to new)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user