Password reset fixes

This commit is contained in:
Ali 2021-07-06 13:49:02 +04:00
parent 6dc3962307
commit 862eb86cae
3 changed files with 26 additions and 8 deletions

View File

@ -49,6 +49,8 @@ public final class TwoFactorDataInputScreen: ViewController {
private let mode: TwoFactorDataInputMode private let mode: TwoFactorDataInputMode
private let stateUpdated: (SetupTwoStepVerificationStateUpdate) -> Void private let stateUpdated: (SetupTwoStepVerificationStateUpdate) -> Void
private let actionDisposable = MetaDisposable() private let actionDisposable = MetaDisposable()
public var passwordRecoveryFailed: (() -> Void)?
public init(sharedContext: SharedAccountContext, engine: SomeTelegramEngine, mode: TwoFactorDataInputMode, stateUpdated: @escaping (SetupTwoStepVerificationStateUpdate) -> Void, presentation: ViewControllerNavigationPresentation = .modalInLargeLayout) { public init(sharedContext: SharedAccountContext, engine: SomeTelegramEngine, mode: TwoFactorDataInputMode, stateUpdated: @escaping (SetupTwoStepVerificationStateUpdate) -> Void, presentation: ViewControllerNavigationPresentation = .modalInLargeLayout) {
self.sharedContext = sharedContext self.sharedContext = sharedContext
@ -516,7 +518,12 @@ public final class TwoFactorDataInputScreen: ViewController {
}) })
})]), in: .window(.root)) })]), in: .window(.root))
case .unauthorized: case .unauthorized:
strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: strongSelf.presentationData.strings.TwoStepAuth_RecoveryFailed, actions: [TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root)) strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: strongSelf.presentationData.strings.TwoStepAuth_RecoveryFailed, actions: [TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_OK, action: {
guard let strongSelf = self else {
return
}
strongSelf.passwordRecoveryFailed?()
})]), in: .window(.root))
} }
default: default:
break break
@ -959,9 +966,9 @@ private final class TwoFactorDataInputScreenNode: ViewControllerTracingNode, UIS
self.scrollNode.canCancelAllTouchesInViews = true self.scrollNode.canCancelAllTouchesInViews = true
switch mode { switch mode {
case .password, .passwordRecovery, .passwordRecoveryEmail, .emailAddress, .updateEmailAddress: case .password, .passwordRecovery, .emailAddress, .updateEmailAddress:
self.monkeyNode = ManagedMonkeyAnimationNode() self.monkeyNode = ManagedMonkeyAnimationNode()
case .emailConfirmation: case .emailConfirmation, .passwordRecoveryEmail:
if let path = getAppBundle().path(forResource: "TwoFactorSetupMail", ofType: "tgs") { if let path = getAppBundle().path(forResource: "TwoFactorSetupMail", ofType: "tgs") {
let animatedStickerNode = AnimatedStickerNode() let animatedStickerNode = AnimatedStickerNode()
animatedStickerNode.setup(source: AnimatedStickerNodeLocalFileSource(path: path), width: 272, height: 272, playbackMode: .once, mode: .direct(cachePathPrefix: nil)) animatedStickerNode.setup(source: AnimatedStickerNodeLocalFileSource(path: path), width: 272, height: 272, playbackMode: .once, mode: .direct(cachePathPrefix: nil))
@ -1268,7 +1275,7 @@ private final class TwoFactorDataInputScreenNode: ViewControllerTracingNode, UIS
return return
} }
switch strongSelf.mode { switch strongSelf.mode {
case .password: case .password, .passwordRecovery:
if strongSelf.inputNodes[1].isFocused { if strongSelf.inputNodes[1].isFocused {
let maxWidth = strongSelf.inputNodes[1].bounds.width let maxWidth = strongSelf.inputNodes[1].bounds.width
@ -1363,7 +1370,7 @@ private final class TwoFactorDataInputScreenNode: ViewControllerTracingNode, UIS
return return
} }
switch strongSelf.mode { switch strongSelf.mode {
case .password: case .password, .passwordRecovery:
textHidden = !textHidden textHidden = !textHidden
for node in strongSelf.inputNodes { for node in strongSelf.inputNodes {
node.updateTextHidden(textHidden) node.updateTextHidden(textHidden)

View File

@ -557,6 +557,17 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
controller = TwoFactorDataInputScreen(sharedContext: self.sharedContext, engine: .unauthorized(TelegramEngineUnauthorized(account: self.account)), mode: .passwordRecoveryEmail(emailPattern: emailPattern, mode: .notAuthorized(syncContacts: syncContacts)), stateUpdated: { _ in controller = TwoFactorDataInputScreen(sharedContext: self.sharedContext, engine: .unauthorized(TelegramEngineUnauthorized(account: self.account)), mode: .passwordRecoveryEmail(emailPattern: emailPattern, mode: .notAuthorized(syncContacts: syncContacts)), stateUpdated: { _ in
}, presentation: .default) }, presentation: .default)
} }
controller.passwordRecoveryFailed = { [weak self] in
guard let strongSelf = self else {
return
}
let _ = (strongSelf.account.postbox.transaction { transaction -> Void in
if let state = transaction.getState() as? UnauthorizedAccountState, case let .passwordRecovery(hint, number, code, _, syncContacts) = state.contents {
transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .passwordEntry(hint: hint, number: number, code: code, suggestReset: true, syncContacts: syncContacts)))
}
}).start()
}
return controller return controller
} }
@ -773,7 +784,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
} }
controllers.append(self.passwordEntryController(hint: hint, suggestReset: suggestReset, syncContacts: syncContacts)) controllers.append(self.passwordEntryController(hint: hint, suggestReset: suggestReset, syncContacts: syncContacts))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty) self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .passwordRecovery(_, _, _, emailPattern, syncContacts): case let .passwordRecovery(hint, _, _, emailPattern, syncContacts):
var controllers: [ViewController] = [] var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty { if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController()) controllers.append(self.splashController())

View File

@ -129,9 +129,9 @@ final class AuthorizationSequencePasswordEntryController: ViewController {
} }
func forgotPressed() { func forgotPressed() {
if self.suggestReset { /*if self.suggestReset {
self.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: self.presentationData), title: nil, text: self.presentationData.strings.TwoStepAuth_RecoveryFailed, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: {})]), in: .window(.root)) self.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: self.presentationData), title: nil, text: self.presentationData.strings.TwoStepAuth_RecoveryFailed, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
} else if self.didForgotWithNoRecovery { } else*/ if self.didForgotWithNoRecovery {
self.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: self.presentationData), title: nil, text: self.presentationData.strings.TwoStepAuth_RecoveryUnavailable, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: {})]), in: .window(.root)) self.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: self.presentationData), title: nil, text: self.presentationData.strings.TwoStepAuth_RecoveryUnavailable, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
} else { } else {
self.forgot?() self.forgot?()