mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-09 13:58:45 +00:00
Handle token change during password update
This commit is contained in:
parent
bff05301f4
commit
d387b55f88
6 changed files with 11 additions and 7 deletions
|
|
@ -661,7 +661,7 @@ interface ApiService {
|
|||
@PUT("user/auth/update-password")
|
||||
suspend fun updatePassword(
|
||||
@Body data: Map<String, String>
|
||||
): HabitResponse<Void>
|
||||
): HabitResponse<UserAuthResponse>
|
||||
|
||||
@POST("user/allocate")
|
||||
suspend fun allocatePoint(
|
||||
|
|
|
|||
|
|
@ -422,7 +422,7 @@ interface ApiClient {
|
|||
oldPassword: String,
|
||||
newPassword: String,
|
||||
newPasswordConfirmation: String
|
||||
): Void?
|
||||
): UserAuthResponse?
|
||||
|
||||
suspend fun allocatePoint(stat: String): Stats?
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import com.habitrpg.android.habitica.models.user.Stats
|
|||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.models.user.UserQuestStatus
|
||||
import com.habitrpg.common.habitica.models.Notification
|
||||
import com.habitrpg.common.habitica.models.auth.UserAuthResponse
|
||||
import com.habitrpg.shared.habitica.models.responses.VerifyUsernameResponse
|
||||
import com.habitrpg.shared.habitica.models.tasks.Attribute
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
|
@ -106,7 +107,7 @@ interface UserRepository : BaseRepository {
|
|||
oldPassword: String,
|
||||
newPassword: String,
|
||||
newPasswordConfirmation: String
|
||||
): Void?
|
||||
): UserAuthResponse?
|
||||
|
||||
suspend fun verifyUsername(username: String): VerifyUsernameResponse?
|
||||
|
||||
|
|
|
|||
|
|
@ -1033,7 +1033,7 @@ class ApiClientImpl(
|
|||
oldPassword: String,
|
||||
newPassword: String,
|
||||
newPasswordConfirmation: String
|
||||
): Void? {
|
||||
): UserAuthResponse? {
|
||||
val updateObject = HashMap<String, String>()
|
||||
updateObject["password"] = oldPassword
|
||||
updateObject["newPassword"] = newPassword
|
||||
|
|
|
|||
|
|
@ -291,11 +291,14 @@ class AccountPreferenceFragment :
|
|||
passwordRepeatEditText?.showErrorIfNecessary()
|
||||
if (passwordEditText?.isValid != true || passwordRepeatEditText?.isValid != true) return@addButton
|
||||
lifecycleScope.launchCatching {
|
||||
userRepository.updatePassword(
|
||||
val response = userRepository.updatePassword(
|
||||
oldPasswordEditText?.text ?: "",
|
||||
passwordEditText.text ?: "",
|
||||
passwordRepeatEditText.text ?: "",
|
||||
)
|
||||
response?.apiToken?.let {
|
||||
viewModel.saveTokens(it, user?.id ?: "")
|
||||
}
|
||||
(activity as? SnackbarActivity)?.showSnackbar(
|
||||
content = context.getString(R.string.password_changed),
|
||||
displayType = HabiticaSnackbar.SnackbarDisplayType.SUCCESS,
|
||||
|
|
@ -340,7 +343,7 @@ class AccountPreferenceFragment :
|
|||
val email =
|
||||
if (showEmail) emailEditText?.text else user?.authentication?.findFirstSocialEmail()
|
||||
lifecycleScope.launchCatching {
|
||||
viewModel.register(
|
||||
val response = viewModel.register(
|
||||
user?.username ?: "",
|
||||
email ?: "",
|
||||
passwordEditText.text ?: "",
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class AuthenticationViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
private fun saveTokens(
|
||||
fun saveTokens(
|
||||
api: String,
|
||||
user: String,
|
||||
) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue