fixed a bug
This commit is contained in:
@@ -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}$")
|
||||
|
||||
@@ -139,7 +139,7 @@ internal class AuthCoordinator(
|
||||
InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD,
|
||||
)
|
||||
val nicknameInput = labeledInput("姓名", "你的真实姓名或昵称")
|
||||
val phoneInput = labeledInput("手机号", "选填", InputType.TYPE_CLASS_PHONE)
|
||||
val phoneInput = labeledInput("手机号", "请输入 11 位手机号", InputType.TYPE_CLASS_PHONE)
|
||||
val statusText = statusText()
|
||||
|
||||
addView(primaryButton("注册") {
|
||||
@@ -151,6 +151,7 @@ internal class AuthCoordinator(
|
||||
username.length < 3 -> statusText.text = "用户名至少 3 个字符"
|
||||
password.length < 8 -> statusText.text = "密码至少 8 位"
|
||||
nickname.isBlank() -> statusText.text = "请填写姓名"
|
||||
!PHONE_PATTERN.matches(phone) -> statusText.text = "请输入有效的 11 位手机号"
|
||||
else -> {
|
||||
statusText.text = "注册中..."
|
||||
userApi.register(username, password, nickname, phone) { result ->
|
||||
|
||||
Reference in New Issue
Block a user