新增邮箱注册页面表单校验

新增邮箱注册页面表单校验,包括:
- 邮箱格式校验
- 密码格式校验(至少8位,
包含大小写字母和数字)
- 确认密码校验
- 服务条款和推广信息勾选校验

新增错误提示,包括:
- 邮箱格式错误
- 密码格式错误
- 确认密码不一致
- 未勾选服务条款
- 未勾选推广信息

优化
用户体验,包括:
- 使用 CheckboxWithLabel 组件优化勾选框样式
- 使用字符串资源
- 调整页面布局
This commit is contained in:
2024-09-06 15:34:27 +08:00
parent b7da2981aa
commit 025f66ca83
8 changed files with 303 additions and 106 deletions

View File

@@ -365,7 +365,14 @@ class AccountServiceImpl : AccountService {
}
override suspend fun registerUserWithPassword(loginName: String, password: String) {
ApiClient.api.register(RegisterRequestBody(loginName, password))
val resp = ApiClient.api.register(RegisterRequestBody(loginName, password))
if (!resp.isSuccessful) {
parseErrorResponse(resp.errorBody())?.let {
throw it.toServiceException()
}
throw ServiceException("Failed to register")
}
}
override suspend fun changeAccountPassword(oldPassword: String, newPassword: String) {

View File

@@ -1,12 +1,43 @@
package com.aiosman.riderpro.data
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import okhttp3.ResponseBody
/**
* 错误返回
*/
class ServiceException(
override val message: String,
val code: Int = 0,
val data: Any? = null
val code: Int? = 0,
val data: Any? = null,
val error: String? = null,
val name: String? = null,
) : Exception(
message
)
)
data class ApiErrorResponse(
@SerializedName("code")
val code: Int?,
@SerializedName("error")
val error: String?,
@SerializedName("message")
val name: String?,
) {
fun toServiceException(): ServiceException {
return ServiceException(
message = error ?: name ?: "",
code = code,
error = error,
name = name
)
}
}
fun parseErrorResponse(errorBody: ResponseBody?): ApiErrorResponse? {
return errorBody?.let {
val gson = Gson()
gson.fromJson(it.charStream(), ApiErrorResponse::class.java)
}
}