找回密码
This commit is contained in:
@@ -9,6 +9,7 @@ data class LoginBean(
|
|||||||
val role: String,
|
val role: String,
|
||||||
val scope: Any
|
val scope: Any
|
||||||
)
|
)
|
||||||
|
|
||||||
data class LoginRequest(
|
data class LoginRequest(
|
||||||
val clientId: String = "428a8310cd442757ae699df5d894f051",
|
val clientId: String = "428a8310cd442757ae699df5d894f051",
|
||||||
val grantType: String,
|
val grantType: String,
|
||||||
|
|||||||
@@ -10,5 +10,7 @@ data class UserInfoBean(
|
|||||||
val avatar: String? = null,
|
val avatar: String? = null,
|
||||||
val role: String? = null,
|
val role: String? = null,
|
||||||
val idCard: String? = null,
|
val idCard: String? = null,
|
||||||
val createTime: String? = null
|
val createTime: String? = null,
|
||||||
|
val optionPassword: String? = null,
|
||||||
|
val optionStatus: String? = null,
|
||||||
): Serializable
|
): Serializable
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.example.defenseapplication.personal
|
package com.example.defenseapplication.personal
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@@ -19,7 +20,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
//个人资料
|
||||||
class PersonalProfileActivity : AppCompatActivity() {
|
class PersonalProfileActivity : AppCompatActivity() {
|
||||||
private lateinit var binding: PersonalProfileActivityBinding
|
private lateinit var binding: PersonalProfileActivityBinding
|
||||||
private var userInfo: UserInfoBean? = null
|
private var userInfo: UserInfoBean? = null
|
||||||
@@ -32,7 +33,9 @@ class PersonalProfileActivity : AppCompatActivity() {
|
|||||||
.statusBarDarkFont(true)
|
.statusBarDarkFont(true)
|
||||||
.titleBar(binding.topBar)
|
.titleBar(binding.topBar)
|
||||||
.init()
|
.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()
|
initView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,15 @@ import android.os.Bundle
|
|||||||
import android.os.CountDownTimer
|
import android.os.CountDownTimer
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import bean.ForgotRequest
|
||||||
import com.example.defenseapplication.R
|
import com.example.defenseapplication.R
|
||||||
import com.example.defenseapplication.databinding.RetrievePasswordActivityBinding
|
import com.example.defenseapplication.databinding.RetrievePasswordActivityBinding
|
||||||
|
import com.example.defenseapplication.utils.RetrofitNetwork
|
||||||
import com.gyf.immersionbar.ImmersionBar
|
import com.gyf.immersionbar.ImmersionBar
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
//找回密码页面
|
//找回密码页面
|
||||||
class RetrievePasswordActivity : AppCompatActivity() {
|
class RetrievePasswordActivity : AppCompatActivity() {
|
||||||
@@ -46,8 +52,27 @@ class RetrievePasswordActivity : AppCompatActivity() {
|
|||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
startCountdown()
|
binding.btnGetCode.isEnabled = false
|
||||||
Toast.makeText(this, String.format(getString(R.string.code_sent_to), phoneNumber), Toast.LENGTH_SHORT).show()
|
|
||||||
|
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 {
|
binding.btnConfirmReset.setOnClickListener {
|
||||||
@@ -96,8 +121,32 @@ class RetrievePasswordActivity : AppCompatActivity() {
|
|||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(this, getString(R.string.reset_success), Toast.LENGTH_SHORT).show()
|
binding.btnConfirmReset.isEnabled = false
|
||||||
finish()
|
|
||||||
|
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")
|
@PUT("/app/forgotPassword")
|
||||||
suspend fun updatePassword(@Body request: UpdatePassword): GetCodeBean<UpdatePassword>
|
suspend fun updatePassword(@Body request: UpdatePassword): GetCodeBean<UpdatePassword>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登陆后手机号找回密码
|
||||||
|
* */
|
||||||
|
@POST("/app/retrievePassword")
|
||||||
|
suspend fun retrievePassword(@Body request: ForgotRequest): GetCodeBean<ForgotRequest>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -448,4 +448,6 @@
|
|||||||
<string name="password_reset_failed">密码重置失败</string>
|
<string name="password_reset_failed">密码重置失败</string>
|
||||||
<string name="user_not_login">用户未登录</string>
|
<string name="user_not_login">用户未登录</string>
|
||||||
<string name="phone_number_empty">手机号为空</string>
|
<string name="phone_number_empty">手机号为空</string>
|
||||||
|
<string name="operation_fail">操作失败</string>
|
||||||
|
<string name="get_user_info_fail">获取用户信息失败</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -452,4 +452,6 @@
|
|||||||
<string name="password_reset_failed">Password reset failed</string>
|
<string name="password_reset_failed">Password reset failed</string>
|
||||||
<string name="user_not_login">User not logged in</string>
|
<string name="user_not_login">User not logged in</string>
|
||||||
<string name="phone_number_empty">Phone number not found</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>
|
</resources>
|
||||||
Reference in New Issue
Block a user