mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-17 23:43:34 +01:00
Fix possible captcha race.
This commit is contained in:
@@ -458,8 +458,8 @@ class RegistrationViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun submitCaptchaToken(context: Context) {
|
||||
val e164 = getCurrentE164() ?: throw IllegalStateException("Can't submit captcha token if no phone number is set!")
|
||||
val captchaToken = store.value.captchaToken ?: throw IllegalStateException("Can't submit captcha token if no captcha token is set!")
|
||||
val e164 = getCurrentE164() ?: return clearChallengesAndBail { Log.w(TAG, "Phone number was null when trying to submit captcha token.") }
|
||||
val captchaToken = store.value.captchaToken ?: return bail { Log.w(TAG, "Captcha token was null when trying to submit captcha token.") }
|
||||
|
||||
store.update {
|
||||
it.copy(captchaToken = null, challengeInProgress = true, inProgress = true)
|
||||
@@ -486,7 +486,7 @@ class RegistrationViewModel : ViewModel() {
|
||||
fun requestAndSubmitPushToken(context: Context) {
|
||||
Log.v(TAG, "validatePushToken()")
|
||||
|
||||
val e164 = getCurrentE164() ?: throw IllegalStateException("Can't submit captcha token if no phone number is set!")
|
||||
val e164 = getCurrentE164() ?: return clearChallengesAndBail { Log.w(TAG, "Phone number was null when trying to submit push token.") }
|
||||
|
||||
viewModelScope.launch {
|
||||
Log.d(TAG, "Getting session in order to perform push token verification…")
|
||||
@@ -1063,6 +1063,22 @@ class RegistrationViewModel : ViewModel() {
|
||||
setInProgress(false)
|
||||
}
|
||||
|
||||
/**
|
||||
* Like [bail], but also clears challenge state. This is needed when challenge handling fails due to missing phone number,
|
||||
* since otherwise the stale challenges would re-trigger the observer on every config change.
|
||||
*/
|
||||
private fun clearChallengesAndBail(logMessage: () -> Unit) {
|
||||
logMessage()
|
||||
store.update {
|
||||
it.copy(
|
||||
inProgress = false,
|
||||
challengesRequested = emptyList(),
|
||||
challengeInProgress = false,
|
||||
captchaToken = null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun registerWithBackupKey(context: Context, backupKey: String, e164: String?, pin: String?, aciIdentityKeyPair: IdentityKeyPair?, pniIdentityKeyPair: IdentityKeyPair?) {
|
||||
setInProgress(true)
|
||||
|
||||
|
||||
@@ -600,6 +600,7 @@ class EnterPhoneNumberFragment : LoggingFragment(R.layout.fragment_registration_
|
||||
private fun updateEnabledControls(showProgress: Boolean, isReRegister: Boolean) {
|
||||
binding.countryCode.isEnabled = !showProgress
|
||||
binding.number.isEnabled = !showProgress
|
||||
countryPickerView.isEnabled = !showProgress
|
||||
binding.cancelButton.visible = !showProgress && isReRegister
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user