找回密码
This commit is contained in:
@@ -9,6 +9,7 @@ data class LoginBean(
|
||||
val role: String,
|
||||
val scope: Any
|
||||
)
|
||||
|
||||
data class LoginRequest(
|
||||
val clientId: String = "428a8310cd442757ae699df5d894f051",
|
||||
val grantType: String,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user