Add missing errors

This commit is contained in:
Ali 2021-07-09 01:15:29 +04:00
parent b8beeabfc6
commit 4e53e050d1
6 changed files with 884 additions and 823 deletions

View File

@ -6557,3 +6557,5 @@ Sorry for the inconvenience.";
"TwoFactorSetup.ResetDone.TitleNoPassword" = "Password Removed";
"TwoFactorSetup.ResetDone.TextNoPassword" = "You can always set a new password in\n\n\nSettings>Privacy & Security>Two-Step Verification";
"TwoFactorSetup.ResetFloodWait" = "You have recently requested a password reset that was canceled. Please wait for %@ before making a new request.";

View File

@ -513,7 +513,19 @@ public final class TwoFactorDataInputScreen: ViewController {
case .declined:
break
case let .error(reason):
break
let text: String
switch reason {
case let .limitExceeded(retryAtTimestamp):
if let retryAtTimestamp = retryAtTimestamp {
let remainingSeconds = retryAtTimestamp - Int32(Date().timeIntervalSince1970)
text = strongSelf.presentationData.strings.TwoFactorSetup_ResetFloodWait(timeIntervalString(strings: strongSelf.presentationData.strings, value: remainingSeconds)).0
} else {
text = strongSelf.presentationData.strings.TwoStepAuth_FloodError
}
case .generic:
text = strongSelf.presentationData.strings.Login_UnknownError
}
strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
}
})
})]), in: .window(.root))

View File

@ -552,7 +552,19 @@ func twoStepVerificationUnlockSettingsController(context: AccountContext, mode:
case .declined:
break
case let .error(reason):
break
let text: String
switch reason {
case let .limitExceeded(retryAtTimestamp):
if let retryAtTimestamp = retryAtTimestamp {
let remainingSeconds = retryAtTimestamp - Int32(Date().timeIntervalSince1970)
text = presentationData.strings.TwoFactorSetup_ResetFloodWait(timeIntervalString(strings: presentationData.strings, value: remainingSeconds)).0
} else {
text = presentationData.strings.TwoStepAuth_FloodError
}
case .generic:
text = presentationData.strings.Login_UnknownError
}
presentControllerImpl?(textAlertController(sharedContext: context.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
}
})
}
@ -568,7 +580,19 @@ func twoStepVerificationUnlockSettingsController(context: AccountContext, mode:
case .declined:
break
case let .error(reason):
break
let text: String
switch reason {
case let .limitExceeded(retryAtTimestamp):
if let retryAtTimestamp = retryAtTimestamp {
let remainingSeconds = retryAtTimestamp - Int32(Date().timeIntervalSince1970)
text = presentationData.strings.TwoFactorSetup_ResetFloodWait(timeIntervalString(strings: presentationData.strings, value: remainingSeconds)).0
} else {
text = presentationData.strings.TwoStepAuth_FloodError
}
case .generic:
text = presentationData.strings.Login_UnknownError
}
presentControllerImpl?(textAlertController(sharedContext: context.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
}
})
})]), ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
@ -858,7 +882,20 @@ func twoStepVerificationUnlockSettingsController(context: AccountContext, mode:
case .declined:
break
case let .error(reason):
break
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let text: String
switch reason {
case let .limitExceeded(retryAtTimestamp):
if let retryAtTimestamp = retryAtTimestamp {
let remainingSeconds = retryAtTimestamp - Int32(Date().timeIntervalSince1970)
text = presentationData.strings.TwoFactorSetup_ResetFloodWait(timeIntervalString(strings: presentationData.strings, value: remainingSeconds)).0
} else {
text = presentationData.strings.TwoStepAuth_FloodError
}
case .generic:
text = presentationData.strings.Login_UnknownError
}
presentControllerImpl?(textAlertController(sharedContext: context.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
}
})
})

View File

@ -395,7 +395,7 @@ func _internal_requestTemporaryTwoStepPasswordToken(account: Account, password:
public enum RequestTwoStepPasswordResetResult {
public enum ErrorReason {
case generic
case limitExceeded
case limitExceeded(retryAtTimestamp: Int32?)
}
case done
@ -406,12 +406,19 @@ public enum RequestTwoStepPasswordResetResult {
func _internal_requestTwoStepPasswordReset(network: Network) -> Signal<RequestTwoStepPasswordResetResult, NoError> {
return network.request(Api.functions.account.resetPassword(), automaticFloodWait: false)
|> map { _ -> RequestTwoStepPasswordResetResult in
return .done
|> map { result -> RequestTwoStepPasswordResetResult in
switch result {
case let .resetPasswordFailedWait(retryDate):
return .error(reason: .limitExceeded(retryAtTimestamp: retryDate))
case .resetPasswordOk:
return .done
case let .resetPasswordRequestedWait(untilDate):
return .waitingForReset(resetAtTimestamp: untilDate)
}
}
|> `catch` { error -> Signal<RequestTwoStepPasswordResetResult, NoError> in
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
return .single(.error(reason: .limitExceeded))
return .single(.error(reason: .limitExceeded(retryAtTimestamp: nil)))
} else if error.errorDescription.hasPrefix("RESET_WAIT_") {
if let remainingSeconds = Int32(error.errorDescription[error.errorDescription.index(error.errorDescription.startIndex, offsetBy: "RESET_WAIT_".count)...]) {
let timestamp = Int32(network.globalTime)