fixed a bug

This commit is contained in:
2026-09-09 12:31:05 +08:00
parent fb64343a9f
commit 9d956183c7
5 changed files with 185 additions and 9 deletions

View File

@@ -106,7 +106,7 @@ class UserApi internal constructor(
username: String,
password: String,
nickname: String? = null,
phone: String? = null,
phone: String,
onComplete: (Result<AuthSession>) -> Unit,
): CancellableRequest = submit(onComplete) {
requestRegisterBlocking(
@@ -234,13 +234,16 @@ class UserApi internal constructor(
username: String,
password: String,
nickname: String?,
phone: String?,
phone: String,
): AuthSession {
val cleanedPhone = phone.trim()
require(cleanedPhone.isNotEmpty()) { "请填写手机号" }
require(PHONE_PATTERN.matches(cleanedPhone)) { "请输入有效的 11 位手机号" }
val root = JSONObject()
.put("username", username)
.put("password", password)
nickname?.takeIf { it.isNotBlank() }?.let { root.put("nickname", it) }
phone?.takeIf { it.isNotBlank() }?.let { root.put("phone", it) }
root.put("phone", cleanedPhone)
val response = request(path, body = root.toString(), method = "POST")
return parseSession(JSONObject(response))
}
@@ -385,3 +388,5 @@ data class SsoExchangeResult(
val phoneBound: Boolean,
val isNewUser: Boolean,
)
private val PHONE_PATTERN = Regex("^1[3-9]\\d{9}$")