From c8a6000b25c186ce104cf6639c7d36e17457a36b Mon Sep 17 00:00:00 2001 From: Alexey Gerasimov Date: Mon, 22 Oct 2018 15:44:17 +0300 Subject: [PATCH 1/6] PassCodeControllerType renamed --- .../Controllers/PassCode/Model/PassCodeHolder.swift | 6 +++--- .../PassCode/Model/PassCodeHolderProtocol.swift | 4 ++-- .../PassCode/View/BasePassCodeViewController.swift | 2 +- .../PassCode/ViewModel/BasePassCodeViewModel.swift | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/Controllers/PassCode/Model/PassCodeHolder.swift b/Sources/Controllers/PassCode/Model/PassCodeHolder.swift index 4780bba..874bd7a 100644 --- a/Sources/Controllers/PassCode/Model/PassCodeHolder.swift +++ b/Sources/Controllers/PassCode/Model/PassCodeHolder.swift @@ -41,7 +41,7 @@ public extension PassCodeHolderProtocol { /// Holds information about pass codes during pass code creation process public class PassCodeHolderCreate: PassCodeHolderProtocol { - public let type: PassCodeControllerType = .create + public let type: PassCodeOperationType = .create private var firstPassCode: String? private var secondPassCode: String? @@ -95,7 +95,7 @@ public class PassCodeHolderCreate: PassCodeHolderProtocol { /// Holds information about pass code during pass code entering process public class PassCodeHolderEnter: PassCodeHolderProtocol { - public let type: PassCodeControllerType = .enter + public let type: PassCodeOperationType = .enter public let enterStep: PassCodeControllerState = .enter public var shouldValidate: Bool { @@ -125,7 +125,7 @@ public class PassCodeHolderEnter: PassCodeHolderProtocol { /// Holds information about pass codes during pass code changing process public class PassCodeHolderChange: PassCodeHolderProtocol { - public let type: PassCodeControllerType = .change + public let type: PassCodeOperationType = .change private var oldPassCode: String? private var newFirstPassCode: String? diff --git a/Sources/Controllers/PassCode/Model/PassCodeHolderProtocol.swift b/Sources/Controllers/PassCode/Model/PassCodeHolderProtocol.swift index d8bcf6c..0537f08 100644 --- a/Sources/Controllers/PassCode/Model/PassCodeHolderProtocol.swift +++ b/Sources/Controllers/PassCode/Model/PassCodeHolderProtocol.swift @@ -25,7 +25,7 @@ public protocol PassCodeHolderProtocol { /// Type of operation with pass code - var type: PassCodeControllerType { get } + var type: PassCodeOperationType { get } /// Operation step var enterStep: PassCodeControllerState { get } @@ -54,7 +54,7 @@ public class PassCodeHolderBuilder { - parameter type: type of pass code controller - returns: pass code information holder, specific by type */ - public static func build(with type: PassCodeControllerType) -> PassCodeHolderProtocol { + public static func build(with type: PassCodeOperationType) -> PassCodeHolderProtocol { switch type { case .create: return PassCodeHolderCreate() diff --git a/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift b/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift index 4fcc766..61032b9 100644 --- a/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift +++ b/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift @@ -32,7 +32,7 @@ public enum PinImageType { } /// Pass code operation type -public enum PassCodeControllerType { +public enum PassCodeOperationType { case create case enter case change diff --git a/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift b/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift index de5533b..005f5c6 100644 --- a/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift +++ b/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift @@ -33,7 +33,7 @@ public enum PassCodeAuthType { /// Base view model for passCodeViewController open class BasePassCodeViewModel: BaseViewModel { - public let controllerType: PassCodeControllerType + public let operationType: PassCodeOperationType public let disposeBag = DisposeBag() @@ -57,10 +57,10 @@ open class BasePassCodeViewModel: BaseViewModel { private var attemptsNumber = 0 - private lazy var passCodeHolder: PassCodeHolderProtocol = PassCodeHolderBuilder.build(with: self.controllerType) + private lazy var passCodeHolder: PassCodeHolderProtocol = PassCodeHolderBuilder.build(with: self.operationType) - public init(controllerType: PassCodeControllerType, passCodeConfiguration: PassCodeConfiguration) { - self.controllerType = controllerType + public init(operationType: PassCodeOperationType, passCodeConfiguration: PassCodeConfiguration) { + self.operationType = operationType self.passCodeConfiguration = passCodeConfiguration bindViewModel() @@ -95,7 +95,7 @@ open class BasePassCodeViewModel: BaseViewModel { public func reset() { passCodeText.value = nil validationResultHolder.value = nil - passCodeControllerStateVariable.value = controllerType == .change ? .oldEnter : .enter + passCodeControllerStateVariable.value = operationType == .change ? .oldEnter : .enter attemptsNumber = 0 passCodeHolder.reset() } From 5c4ba04e2c2095166bd902114d2d06d1056aec76 Mon Sep 17 00:00:00 2001 From: Alexey Gerasimov Date: Mon, 22 Oct 2018 15:44:47 +0300 Subject: [PATCH 2/6] LegacyConfigurableController PassCode fix --- .../Controllers/PassCode/View/BasePassCodeViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift b/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift index 61032b9..4a8e378 100644 --- a/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift +++ b/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift @@ -288,7 +288,7 @@ open class BasePassCodeViewController: UIViewController, LegacyConfigurableContr open func addViews() {} - open func setAppearance() {} + open func configureAppearance() {} open func configureBarButtons() {} From 77309f0b775307544934b3ae79288d65ff8b8446 Mon Sep 17 00:00:00 2001 From: Alexey Gerasimov Date: Mon, 22 Oct 2018 15:48:03 +0300 Subject: [PATCH 3/6] Make showBiometricsRequestIfNeeded method public --- .../View/BasePassCodeViewController.swift | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift b/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift index 4a8e378..ffd8598 100644 --- a/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift +++ b/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift @@ -150,16 +150,6 @@ open class BasePassCodeViewController: UIViewController, LegacyConfigurableContr } } - private func showBiometricsRequestIfNeeded() { - guard viewModel.isBiometricsEnabled && viewModel.controllerType == .enter else { - return - } - - viewModel.authenticateUsingBiometrics(with: biometricsAuthorizationHint, - fallback: biometricsFallbackButtonTitle, - cancel: biometricsCancelButtonTitle) - } - private func resetUI() { resetDotsUI() viewModel.reset() @@ -251,6 +241,17 @@ open class BasePassCodeViewController: UIViewController, LegacyConfigurableContr fakeTextField.resignFirstResponder() } + /// Show biometrics system UI if applicable + func showBiometricsRequestIfNeeded() { + guard viewModel.isBiometricsEnabled && viewModel.operationType == .enter else { + return + } + + viewModel.authenticateUsingBiometrics(with: biometricsAuthorizationHint, + fallback: biometricsFallbackButtonTitle, + cancel: biometricsCancelButtonTitle) + } + // MARK: - ConfigurableController open func bindViews() { From aec1b23df7e430369232cd8df34720a07ace2366 Mon Sep 17 00:00:00 2001 From: Alexey Gerasimov Date: Mon, 22 Oct 2018 16:24:55 +0300 Subject: [PATCH 4/6] Too many attempts logic updated --- .../PassCode/Model/PassCodeError.swift | 12 ++++--- .../ViewModel/BasePassCodeViewModel.swift | 33 ++++++++++++------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Sources/Controllers/PassCode/Model/PassCodeError.swift b/Sources/Controllers/PassCode/Model/PassCodeError.swift index ca7ebed..6e2a86b 100644 --- a/Sources/Controllers/PassCode/Model/PassCodeError.swift +++ b/Sources/Controllers/PassCode/Model/PassCodeError.swift @@ -21,13 +21,15 @@ // /// Describes error, which may occur during pass code entering -/// - codesNotMatch: Different codes -/// - wrongCode: Value is remaining attemps -/// - tooManyAttempts: Attempts limit reached public enum PassCodeError: Error { + /// Different codes case codesNotMatch - case wrongCode(Int) - case tooManyAttempts + + /// Value is remaining attemps + case wrongCode(attemptsRemaining: Int) + + /// Attempts limit reached (for create, change or enter) + case tooManyAttempts(type: PassCodeOperationType) } public extension PassCodeError { diff --git a/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift b/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift index 005f5c6..7b17c35 100644 --- a/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift +++ b/Sources/Controllers/PassCode/ViewModel/BasePassCodeViewModel.swift @@ -197,21 +197,32 @@ extension BasePassCodeViewModel { return } + switch passCodeHolder.type { + case .create where passCodeHolder.enterStep == .enter: + attemptsNumber += 1 + case .change where passCodeHolder.enterStep == .enter: + attemptsNumber += 1 + case .enter: + attemptsNumber += 1 + default: + break + } + var validationResult = passCodeHolder.validate() - let passCodeValidationForPassCodeChange = passCodeHolder.type == .change && passCodeHolder.enterStep == .newEnter + // if entered (in .enter mode) code is invalid -> .wrongCode + if passCodeHolder.type == .enter, + let passCode = validationResult.passCode, + !isEnteredPassCodeValid(passCode) { - if passCodeHolder.type == .enter || passCodeValidationForPassCodeChange { - attemptsNumber += 1 + let remainingAttemptsCount = passCodeConfiguration.maxAttemptsNumber - attemptsNumber + validationResult = .invalid(.wrongCode(attemptsRemaining: remainingAttemptsCount)) + } - if let passCode = validationResult.passCode, !isEnteredPassCodeValid(passCode) { - validationResult = .invalid(.wrongCode(passCodeConfiguration.maxAttemptsNumber - attemptsNumber)) - } - - if (!validationResult.isValid && attemptsNumber == Int(passCodeConfiguration.maxAttemptsNumber)) || - attemptsNumber > Int(passCodeConfiguration.maxAttemptsNumber) { - validationResult = .invalid(.tooManyAttempts) - } + // if entered code (in any mode) is mismatched too many times -> .tooManyAttempts + if (!validationResult.isValid && attemptsNumber == passCodeConfiguration.maxAttemptsNumber) || + attemptsNumber > passCodeConfiguration.maxAttemptsNumber { + validationResult = .invalid(.tooManyAttempts(type: operationType)) } if !validationResult.isValid { From d8285db06f62e72a631997416f96f7a879530999 Mon Sep 17 00:00:00 2001 From: Alexey Gerasimov Date: Mon, 22 Oct 2018 16:28:40 +0300 Subject: [PATCH 5/6] Forgotten public --- .../Controllers/PassCode/View/BasePassCodeViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift b/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift index ffd8598..81378fe 100644 --- a/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift +++ b/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift @@ -242,7 +242,7 @@ open class BasePassCodeViewController: UIViewController, LegacyConfigurableContr } /// Show biometrics system UI if applicable - func showBiometricsRequestIfNeeded() { + public func showBiometricsRequestIfNeeded() { guard viewModel.isBiometricsEnabled && viewModel.operationType == .enter else { return } From 94aaeba4ad883a2a6649ece2357691919fdc5d59 Mon Sep 17 00:00:00 2001 From: Alexey Gerasimov Date: Mon, 22 Oct 2018 16:38:03 +0300 Subject: [PATCH 6/6] Version update --- CHANGELOG.md | 6 ++++++ LeadKitAdditions.podspec | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b368eda..69695ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 0.3.6 + +- **Update**: PassCodeError, now emmit `tooManyAttempts` in any operation (*create* / *change* / *enter*) type. +- **Update**: Rename `PassCodeControllerType` to `PassCodeOperationType`. +- **Update**: `showBiometricsRequestIfNeeded` method become public. + ### 0.3.5 - **Update**: Migrate to Swift 4.2 & Xcode 10. Update dependencies. diff --git a/LeadKitAdditions.podspec b/LeadKitAdditions.podspec index 7974392..f67dce4 100644 --- a/LeadKitAdditions.podspec +++ b/LeadKitAdditions.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKitAdditions" - s.version = "0.3.5" + s.version = "0.3.6" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKitAdditions" s.license = "Apache License, Version 2.0"