Pass soft logout credentials on coordinator initialization

This commit is contained in:
ismailgulek
2022-06-08 15:59:52 +03:00
parent 3cd1adb312
commit 7cd40c7a26
6 changed files with 26 additions and 29 deletions
@@ -42,9 +42,6 @@ protocol AuthenticationCoordinatorProtocol: Coordinator, Presentable {
/// Update the screen to display registration or login.
func update(authenticationFlow: AuthenticationFlow)
/// Update the screen to use any credentials to use after a soft logout has taken place.
func update(softLogoutCredentials: MXCredentials)
/// Indicates to the coordinator to display any pending screens if it was created with
/// the `canPresentAdditionalScreens` parameter set to `false`
func presentPendingScreensIfNecessary()
@@ -22,6 +22,8 @@ struct LegacyAuthenticationCoordinatorParameters {
let navigationRouter: NavigationRouterType
/// Whether or not the coordinator should show the loading spinner, key verification etc.
let canPresentAdditionalScreens: Bool
/// The credentials to use if a soft logout has taken place.
let softLogoutCredentials: MXCredentials?
}
/// A coordinator that handles authentication, verification and setting a PIN using the old UIViewController flow for iOS 12 & 13.
@@ -61,6 +63,7 @@ final class LegacyAuthenticationCoordinator: NSObject, AuthenticationCoordinator
self.canPresentAdditionalScreens = parameters.canPresentAdditionalScreens
let authenticationViewController = AuthenticationViewController()
authenticationViewController.softLogoutCredentials = parameters.softLogoutCredentials
self.authenticationViewController = authenticationViewController
// Preload the view as this can a second and lock up the UI at presentation.
@@ -87,10 +90,6 @@ final class LegacyAuthenticationCoordinator: NSObject, AuthenticationCoordinator
authenticationViewController.authType = authenticationFlow.mxkType
}
func update(softLogoutCredentials: MXCredentials) {
authenticationViewController.softLogoutCredentials = softLogoutCredentials
}
func presentPendingScreensIfNecessary() {
canPresentAdditionalScreens = true
@@ -717,9 +717,6 @@ extension AuthenticationCoordinator {
// unused
}
func update(softLogoutCredentials: MXCredentials) {
// unused
}
}
// MARK: - AuthFallBackViewControllerDelegate
@@ -86,8 +86,10 @@ final class OnboardingCoordinator: NSObject, OnboardingCoordinatorProtocol {
self.parameters = parameters
// Preload the legacy authVC (it is *really* slow to load in realtime)
let authenticationParameters = LegacyAuthenticationCoordinatorParameters(navigationRouter: parameters.router, canPresentAdditionalScreens: false)
legacyAuthenticationCoordinator = LegacyAuthenticationCoordinator(parameters: authenticationParameters)
let params = LegacyAuthenticationCoordinatorParameters(navigationRouter: parameters.router,
canPresentAdditionalScreens: false,
softLogoutCredentials: parameters.softLogoutCredentials)
legacyAuthenticationCoordinator = LegacyAuthenticationCoordinator(parameters: params)
super.init()
}
@@ -96,8 +98,10 @@ final class OnboardingCoordinator: NSObject, OnboardingCoordinatorProtocol {
func start() {
if parameters.softLogoutCredentials != nil {
beginAuthentication(with: .login) {
if BuildSettings.onboardingEnableNewAuthenticationFlow {
beginAuthentication(with: .login)
} else {
showLegacyAuthenticationScreen()
}
} else if BuildSettings.authScreenShowRegister {
showSplashScreen()
@@ -194,7 +198,7 @@ final class OnboardingCoordinator: NSObject, OnboardingCoordinatorProtocol {
// MARK: - Authentication
/// Show the authentication flow, starting at the specified initial screen.
private func beginAuthentication(with initialScreen: AuthenticationCoordinator.EntryPoint, onStart: @escaping () -> Void) {
private func beginAuthentication(with initialScreen: AuthenticationCoordinator.EntryPoint, onStart: (() -> Void)? = nil) {
MXLog.debug("[OnboardingCoordinator] beginAuthentication")
let parameters = AuthenticationCoordinatorParameters(navigationRouter: navigationRouter,
@@ -207,13 +211,15 @@ final class OnboardingCoordinator: NSObject, OnboardingCoordinatorProtocol {
switch result {
case .didStart:
onStart()
onStart?()
case .didLogin(let session, let authenticationFlow, let authenticationType):
self.authenticationCoordinator(coordinator, didLoginWith: session, and: authenticationFlow, using: authenticationType)
case .didComplete:
self.authenticationCoordinatorDidComplete(coordinator)
case .clearAllData:
break
self.isShowingLegacyAuthentication = false
self.authenticationFinished = false
AppDelegate.theDelegate().logoutSendingRequestServer(true, completion: nil)
case .cancel(let flow):
self.cancelAuthentication(flow: flow)
}
@@ -246,11 +252,7 @@ final class OnboardingCoordinator: NSObject, OnboardingCoordinatorProtocol {
}
coordinator.customServerFieldsVisible = useCaseResult == .customServer
if let softLogoutCredentials = parameters.softLogoutCredentials {
coordinator.update(softLogoutCredentials: softLogoutCredentials)
}
authenticationCoordinator = coordinator
coordinator.start()
@@ -21,7 +21,13 @@ import Foundation
@objcMembers
class OnboardingCoordinatorBridgePresenterParameters: NSObject {
/// The credentials to use after a soft logout has taken place.
var softLogoutCredentials: MXCredentials?
let softLogoutCredentials: MXCredentials?
init(softLogoutCredentials: MXCredentials?) {
self.softLogoutCredentials = softLogoutCredentials
super.init()
}
}
/// OnboardingCoordinatorBridgePresenter enables to start OnboardingCoordinator from a view controller.
+2 -6
View File
@@ -475,12 +475,8 @@
// TODO: Manage the onboarding coordinator at the AppCoordinator level
- (void)presentOnboardingFlow
{
OnboardingCoordinatorBridgePresenterParameters *parameters = [[OnboardingCoordinatorBridgePresenterParameters alloc] init];
if (self.softLogoutCredentials)
{
parameters.softLogoutCredentials = self.softLogoutCredentials;
self.softLogoutCredentials = nil;
}
OnboardingCoordinatorBridgePresenterParameters *parameters = [[OnboardingCoordinatorBridgePresenterParameters alloc] initWithSoftLogoutCredentials:self.softLogoutCredentials];
self.softLogoutCredentials = nil;
MXWeakify(self);
OnboardingCoordinatorBridgePresenter *onboardingCoordinatorBridgePresenter = [[OnboardingCoordinatorBridgePresenter alloc] initWith:parameters];