找回密码

This commit is contained in:
2026-05-21 17:54:49 +08:00
parent 888382f7ce
commit d066886b66
7 changed files with 73 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ data class LoginBean(
val role: String,
val scope: Any
)
data class LoginRequest(
val clientId: String = "428a8310cd442757ae699df5d894f051",
val grantType: String,

View File

@@ -10,5 +10,7 @@ data class UserInfoBean(
val avatar: String? = null,
val role: String? = null,
val idCard: String? = null,
val createTime: String? = null
val createTime: String? = null,
val optionPassword: String? = null,
val optionStatus: String? = null,
): Serializable

View File

@@ -1,5 +1,6 @@
package com.example.defenseapplication.personal
import android.os.Build
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
@@ -19,7 +20,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
//个人资料
class PersonalProfileActivity : AppCompatActivity() {
private lateinit var binding: PersonalProfileActivityBinding
private var userInfo: UserInfoBean? = null
@@ -32,7 +33,9 @@ class PersonalProfileActivity : AppCompatActivity() {
.statusBarDarkFont(true)
.titleBar(binding.topBar)
.init()
userInfo = intent.getParcelableExtra("userInfo", UserInfoBean::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
userInfo = intent.getParcelableExtra("userInfo", UserInfoBean::class.java)
}
initView()
}

View File

@@ -4,9 +4,15 @@ import android.os.Bundle
import android.os.CountDownTimer
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import bean.ForgotRequest
import com.example.defenseapplication.R
import com.example.defenseapplication.databinding.RetrievePasswordActivityBinding
import com.example.defenseapplication.utils.RetrofitNetwork
import com.gyf.immersionbar.ImmersionBar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
//找回密码页面
class RetrievePasswordActivity : AppCompatActivity() {
@@ -46,8 +52,27 @@ class RetrievePasswordActivity : AppCompatActivity() {
return@setOnClickListener
}
startCountdown()
Toast.makeText(this, String.format(getString(R.string.code_sent_to), phoneNumber), Toast.LENGTH_SHORT).show()
binding.btnGetCode.isEnabled = false
CoroutineScope(Dispatchers.IO).launch {
try {
val response = RetrofitNetwork.getNetworkService().getCode(phoneNumber)
withContext(Dispatchers.Main) {
if (response.code == 200) {
startCountdown()
Toast.makeText(this@RetrievePasswordActivity, String.format(getString(R.string.code_sent_to), phoneNumber), Toast.LENGTH_SHORT).show()
} else {
binding.btnGetCode.isEnabled = true
Toast.makeText(this@RetrievePasswordActivity, response.msg, Toast.LENGTH_SHORT).show()
}
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
binding.btnGetCode.isEnabled = true
Toast.makeText(this@RetrievePasswordActivity, getString(R.string.network_error), Toast.LENGTH_SHORT).show()
}
}
}
}
binding.btnConfirmReset.setOnClickListener {
@@ -96,8 +121,32 @@ class RetrievePasswordActivity : AppCompatActivity() {
return@setOnClickListener
}
Toast.makeText(this, getString(R.string.reset_success), Toast.LENGTH_SHORT).show()
finish()
binding.btnConfirmReset.isEnabled = false
CoroutineScope(Dispatchers.IO).launch {
try {
val forgotRequest = ForgotRequest(
phonenumber = phoneNumber,
smsCode = verificationCode,
password = newPassword
)
val response = RetrofitNetwork.getNetworkService().retrievePassword(forgotRequest)
withContext(Dispatchers.Main) {
binding.btnConfirmReset.isEnabled = true
if (response.code == 200) {
Toast.makeText(this@RetrievePasswordActivity, getString(R.string.reset_success), Toast.LENGTH_SHORT).show()
finish()
} else {
Toast.makeText(this@RetrievePasswordActivity, response.msg, Toast.LENGTH_SHORT).show()
}
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
binding.btnConfirmReset.isEnabled = true
Toast.makeText(this@RetrievePasswordActivity, getString(R.string.network_error), Toast.LENGTH_SHORT).show()
}
}
}
}
}

View File

@@ -150,6 +150,13 @@ interface ApiService {
@PUT("/app/forgotPassword")
suspend fun updatePassword(@Body request: UpdatePassword): GetCodeBean<UpdatePassword>
/**
* 登陆后手机号找回密码
* */
@POST("/app/retrievePassword")
suspend fun retrievePassword(@Body request: ForgotRequest): GetCodeBean<ForgotRequest>

View File

@@ -448,4 +448,6 @@
<string name="password_reset_failed">密码重置失败</string>
<string name="user_not_login">用户未登录</string>
<string name="phone_number_empty">手机号为空</string>
<string name="operation_fail">操作失败</string>
<string name="get_user_info_fail">获取用户信息失败</string>
</resources>

View File

@@ -452,4 +452,6 @@
<string name="password_reset_failed">Password reset failed</string>
<string name="user_not_login">User not logged in</string>
<string name="phone_number_empty">Phone number not found</string>
<string name="operation_fail">Operation failed</string>
<string name="get_user_info_fail">Failed to get user info</string>
</resources>