More 2FA improvements

This commit is contained in:
Peter 2018-11-12 02:56:13 +04:00
parent 5266955059
commit 66e562d6c5
4 changed files with 35 additions and 9 deletions

View File

@ -568,13 +568,9 @@ final class SecureIdAuthController: ViewController {
if let password = password {
strongSelf.checkPassword(password: password, inBackground: true, completion: { [weak controller] in
controller?.dismiss()
if let strongSelf = self {
strongSelf.present(OverlayStatusController(theme: strongSelf.presentationData.theme, strings: strongSelf.presentationData.strings, type: .genericSuccess(strongSelf.presentationData.strings.TwoStepAuth_EnabledSuccess)), in: .window(.root))
}
})
} else if shouldDismiss {
controller.dismiss()
strongSelf.present(OverlayStatusController(theme: strongSelf.presentationData.theme, strings: strongSelf.presentationData.strings, type: .genericSuccess(strongSelf.presentationData.strings.TwoStepAuth_EnabledSuccess)), in: .window(.root))
}
}
})

View File

@ -29,6 +29,7 @@ final class SetupTwoStepVerificationContentNode: ASDisplayNode, UITextFieldDeleg
private let rightActionButton: HighlightableButtonNode
private var isEnabled = true
private var clearOnce: Bool = false
init(theme: PresentationTheme, kind: SetupTwoStepVerificationStateKind, title: String, subtitle: String, inputType: SetupTwoStepVerificationInputType, placeholder: String, text: String, isPassword: Bool, textUpdated: @escaping (String) -> Void, returnPressed: @escaping () -> Void, leftAction: SetupTwoStepVerificationContentAction?, rightAction: SetupTwoStepVerificationContentAction?) {
self.leftAction = leftAction
@ -153,10 +154,25 @@ final class SetupTwoStepVerificationContentNode: ASDisplayNode, UITextFieldDeleg
self.inputNode.textField.becomeFirstResponder()
}
func dataEntryError() {
self.clearOnce = true
}
@objc private func inputNodeTextChanged(_ textField: UITextField) {
self.textUpdated(textField.text ?? "")
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if self.clearOnce {
self.clearOnce = false
if range.length > string.count {
textField.text = ""
return false
}
}
return true
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.returnPressed()
return false

View File

@ -32,7 +32,7 @@ private enum EnterEmailState: Equatable {
private enum ConfirmEmailState: Equatable {
case create(password: String, hint: String, email: String)
case add(password: String, hasSecureValues: Bool, email: String)
case add(password: String, hadRecoveryEmail: Bool, hasSecureValues: Bool, email: String)
case confirm(password: String?, hasSecureValues: Bool, pattern: String, codeLength: Int32?)
}
@ -326,8 +326,18 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
}, transition: .animated(duration: 0.5, curve: .spring))
}))
})
case let .add(_, _, email):
case let .add(password, hadRecoveryEmail, hasSecureValues, email):
emailPattern = email
leftAction = SetupTwoStepVerificationContentAction(title: "Change E-Mail", action: { [weak self] in
guard let strongSelf = self else {
return
}
strongSelf.updateState({ state in
var state = state
state.data.state = .enterEmail(state: .add(hadRecoveryEmail: hadRecoveryEmail, hasSecureValues: hasSecureValues, password: password), email: "")
return state
}, transition: .animated(duration: 0.5, curve: .spring))
})
case let .confirm(_, _, pattern, _):
emailPattern = pattern
}
@ -541,7 +551,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
return state
}, transition: .animated(duration: 0.5, curve: .spring))
}))
case let .add(_, hasSecureValues, password):
case let .add(hadRecoveryEmail, hasSecureValues, password):
strongSelf.updateState({ state in
var state = state
state.data.activity = true
@ -561,7 +571,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
break
case let .password(password, pendingEmail):
if let pendingEmail = pendingEmail {
state.data.state = .confirmEmail(state: .add(password: password, hasSecureValues: hasSecureValues, email: email), pattern: pendingEmail.pattern, codeLength: pendingEmail.codeLength, code: "")
state.data.state = .confirmEmail(state: .add(password: password, hadRecoveryEmail: hadRecoveryEmail, hasSecureValues: hasSecureValues, email: email), pattern: pendingEmail.pattern, codeLength: pendingEmail.codeLength, code: "")
strongSelf.stateUpdated(.awaitingEmailConfirmation(password: password, pattern: pendingEmail.pattern, codeLength: pendingEmail.codeLength), false)
} else {
strongSelf.stateUpdated(.passwordSet(password: password, hasRecoveryEmail: true, hasSecureValues: hasSecureValues), true)
@ -598,6 +608,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
text = strongSelf.presentationData.strings.TwoStepAuth_EmailInvalid
case .invalidCode:
text = strongSelf.presentationData.strings.Login_InvalidCodeError
strongSelf.contentNode?.dataEntryError()
case .expired:
text = strongSelf.presentationData.strings.TwoStepAuth_EmailCodeExpired
case .flood:
@ -619,7 +630,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
switch confirmState {
case let .create(password, _, _):
strongSelf.stateUpdated(.passwordSet(password: password, hasRecoveryEmail: true, hasSecureValues: false), true)
case let .add(password, hasSecureValues, email):
case let .add(password, _, hasSecureValues, email):
strongSelf.stateUpdated(.passwordSet(password: password, hasRecoveryEmail: !email.isEmpty, hasSecureValues: hasSecureValues), true)
case let .confirm(password, hasSecureValues, _, _):
strongSelf.stateUpdated(.passwordSet(password: password, hasRecoveryEmail: true, hasSecureValues: hasSecureValues), true)

View File

@ -471,6 +471,9 @@ func twoStepVerificationUnlockSettingsController(account: Account, mode: TwoStep
dataPromise.set(.single(TwoStepVerificationUnlockSettingsControllerData.access(configuration: .notSet(pendingEmail: nil))))
controller?.view.endEditing(true)
controller?.dismiss()
let presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 }
presentControllerImpl?(OverlayStatusController(theme: presentationData.theme, strings: presentationData.strings, type: .genericSuccess(presentationData.strings.TwoStepAuth_DisableSuccess)), nil)
}
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
}, error: { _ in