Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions FlowCrypt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
2C141B2F274578C20038A3F8 /* KeyInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C141B2E274578C20038A3F8 /* KeyInfo.swift */; };
2C2A3B4B2719EE6100B7F27B /* KeyServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C2A3B4A2719EE6100B7F27B /* KeyServiceTests.swift */; };
2C2A3B4D2719EF7300B7F27B /* PassPhraseServiceMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C2A3B4C2719EF7300B7F27B /* PassPhraseServiceMock.swift */; };
2C339B07275CB136005DEA79 /* FatalErrorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C339B06275CB136005DEA79 /* FatalErrorViewController.swift */; };
2C4E60F72757D91A00DE5770 /* EncryptedStorageMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C4E60F62757D91A00DE5770 /* EncryptedStorageMock.swift */; };
2C60AB0C272564D40040D7F2 /* InvalidStorageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C60AB0B272564D40040D7F2 /* InvalidStorageViewController.swift */; };
2CAF25322756C37E005C7C7C /* AppContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CAF25312756C37E005C7C7C /* AppContext.swift */; };
Expand Down Expand Up @@ -451,7 +450,6 @@
2C141B2E274578C20038A3F8 /* KeyInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyInfo.swift; sourceTree = "<group>"; };
2C2A3B4A2719EE6100B7F27B /* KeyServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyServiceTests.swift; sourceTree = "<group>"; };
2C2A3B4C2719EF7300B7F27B /* PassPhraseServiceMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PassPhraseServiceMock.swift; sourceTree = "<group>"; };
2C339B06275CB136005DEA79 /* FatalErrorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FatalErrorViewController.swift; sourceTree = "<group>"; };
2C4E60F62757D91A00DE5770 /* EncryptedStorageMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptedStorageMock.swift; sourceTree = "<group>"; };
2C60AB0B272564D40040D7F2 /* InvalidStorageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvalidStorageViewController.swift; sourceTree = "<group>"; };
2CAF25312756C37E005C7C7C /* AppContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppContext.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1963,7 +1961,6 @@
isa = PBXGroup;
children = (
D24F4C2123E2359B00C5EEE4 /* BootstrapViewController.swift */,
2C339B06275CB136005DEA79 /* FatalErrorViewController.swift */,
2C60AB0B272564D40040D7F2 /* InvalidStorageViewController.swift */,
);
path = Bootstrap;
Expand Down Expand Up @@ -2537,7 +2534,6 @@
D2A9CA3D242619EC00E1D898 /* SignInViewDecorator.swift in Sources */,
9F4300CC2571045B00791CFB /* InboxViewControllerContainerDecorator.swift in Sources */,
9F4163E6266520B600106194 /* CommonNodesInputs.swift in Sources */,
2C339B07275CB136005DEA79 /* FatalErrorViewController.swift in Sources */,
9F883912271F242900669B56 /* ThreadDetailsDecorator.swift in Sources */,
04B472951ECE29F600B8266F /* MyMenuViewController.swift in Sources */,
51B4AE5327144E590001F33B /* PubKey.swift in Sources */,
Expand Down
96 changes: 0 additions & 96 deletions FlowCrypt/Controllers/Bootstrap/FatalErrorViewController.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ extension SetupBackupsViewController {
}

func handleBackButtonTap() {
appContext.globalRouter.signOut(appContext: appContext)
do {
try appContext.globalRouter.signOut(appContext: appContext)
} catch {
showAlert(message: error.localizedDescription)
}
}

private func moveToMainFlow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ class SetupCreatePassphraseAbstractViewController: TableNodeViewController, Pass
}

func handleBackButtonTap() {
appContext.globalRouter.signOut(appContext: self.appContext)
do {
try appContext.globalRouter.signOut(appContext: self.appContext)
} catch {
showAlert(message: error.localizedDescription)
}
}
}

Expand Down
19 changes: 10 additions & 9 deletions FlowCrypt/Controllers/Setup/SetupInitialViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ extension SetupInitialViewController {
}
}

private func handleOtherAccount() {
appContext.globalRouter.signOut(appContext: appContext)
private func signOut() {
do {
try appContext.globalRouter.signOut(appContext: appContext)
} catch {
showAlert(message: error.localizedDescription)
}
}

private func handle(error: Error) {
Expand All @@ -148,8 +152,7 @@ extension SetupInitialViewController {
state = .searchingKeyBackupsInInbox
case .inconsistentClientConfiguration(let error):
showAlert(message: error.description) { [weak self] in
guard let self = self else { return }
self.appContext.globalRouter.signOut(appContext: self.appContext)
self?.signOut()
}
}
}
Expand All @@ -168,14 +171,12 @@ extension SetupInitialViewController {
self?.state = .fetchingKeysFromEKM
},
onOk: { [weak self] in
guard let self = self else { return }
self.appContext.globalRouter.signOut(appContext: self.appContext)
self?.signOut()
}
)
case .keysAreNotDecrypted:
showAlert(message: "organisational_rules_ekm_keys_are_not_decrypted_error".localized, onOk: { [weak self] in
guard let self = self else { return }
self.appContext.globalRouter.signOut(appContext: self.appContext)
self?.signOut()
})
}
} catch {
Expand Down Expand Up @@ -276,7 +277,7 @@ extension SetupInitialViewController {
}
case .anotherAccount:
return ButtonCellNode(input: .chooseAnotherAccount) { [weak self] in
self?.handleOtherAccount()
self?.signOut()
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions FlowCrypt/Controllers/SideMenu/Menu/MyMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ extension MyMenuViewController {
return
}

appContext.globalRouter.switchActive(user: account, appContext: appContext)
do {
try appContext.globalRouter.switchActive(user: account, appContext: appContext)
} catch {
showAlert(message: error.localizedDescription)
}
}
}

Expand Down Expand Up @@ -298,7 +302,11 @@ extension MyMenuViewController {
}
sideMenuController()?.setContentViewController(SettingsViewController(appContext: appContext))
case .logOut:
appContext.globalRouter.signOut(appContext: appContext)
do {
try appContext.globalRouter.signOut(appContext: appContext)
} catch {
showAlert(message: error.localizedDescription)
}
}
}

Expand Down
72 changes: 37 additions & 35 deletions FlowCrypt/Functionality/Services/GlobalRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ protocol GlobalRouterType {
func proceed()
func signIn(appContext: AppContext, route: GlobalRoutingType) async
func askForContactsPermission(for route: GlobalRoutingType, appContext: AppContext) async throws
func switchActive(user: User, appContext: AppContext)
func signOut(appContext: AppContext)
func switchActive(user: User, appContext: AppContext) throws
func signOut(appContext: AppContext) throws
}

enum GlobalRoutingType {
Expand Down Expand Up @@ -79,23 +79,18 @@ extension GlobalRouter: GlobalRouterType {
}
} catch {
logger.logError("Failed to sign in due to \(error.localizedDescription)")
handle(error: error, appContext: appContext)
handleSignInError(error: error, appContext: appContext)
}
}

func signOut(appContext: AppContext) {
do {
if let session = try appContext.userAccountService.startActiveSessionForNextUser() {
logger.logInfo("Start session for another email user \(session)")
proceed(with: appContext.withSession(session))
} else {
logger.logInfo("Sign out")
appContext.userAccountService.cleanup()
proceed()
}
} catch {
logger.logError("Failed to sign out due to \(error.localizedDescription)")
handle(error: error, appContext: appContext)
func signOut(appContext: AppContext) throws {
if let session = try appContext.userAccountService.startActiveSessionForNextUser() {
logger.logInfo("Start session for another email user \(session)")
proceed(with: appContext.withSession(session))
} else {
logger.logInfo("Sign out")
appContext.userAccountService.cleanup()
proceed()
}
}

Expand Down Expand Up @@ -124,18 +119,13 @@ extension GlobalRouter: GlobalRouterType {
}
}

func switchActive(user: User, appContext: AppContext) {
func switchActive(user: User, appContext: AppContext) throws {
logger.logInfo("Switching active user \(user)")
do {
guard let session = try appContext.userAccountService.switchActiveSessionFor(user: user) else {
logger.logWarning("Can't switch active user with \(user.email)")
return
}
proceed(with: appContext.withSession(session))
} catch {
logger.logError("Failed to switch active user due to \(error.localizedDescription)")
handle(error: error, appContext: appContext)
guard let session = try appContext.userAccountService.switchActiveSessionFor(user: user) else {
logger.logWarning("Can't switch active user with \(user.email)")
return
}
proceed(with: appContext.withSession(session))
}

@MainActor
Expand All @@ -157,15 +147,27 @@ extension GlobalRouter: GlobalRouterType {
}

@MainActor
private func handle(error: Error, appContext: AppContext) {
if let gmailUserError = error as? GoogleUserServiceError,
case .userNotAllowedAllNeededScopes = gmailUserError {
logger.logInfo("gmail login failed with error \(gmailUserError.errorMessage)")
let navigationController = keyWindow.rootViewController?.navigationController
let checkAuthViewController = CheckMailAuthViewController(appContext: appContext)
navigationController?.pushViewController(checkAuthViewController, animated: true)
} else {
keyWindow.rootViewController = FatalErrorViewController(error: error)
private func handleSignInError(error: Error, appContext: AppContext) {
if let gmailUserError = error as? GoogleUserServiceError {
logger.logInfo("Gmail login failed with error: \(gmailUserError.errorMessage)")

if case .cancelledAuthorization = gmailUserError {
proceed()
return
}

if case .userNotAllowedAllNeededScopes = gmailUserError {
let navigationController = keyWindow.rootViewController?.navigationController
let checkAuthViewController = CheckMailAuthViewController(appContext: appContext)
navigationController?.pushViewController(checkAuthViewController, animated: true)
return
}
}

keyWindow.rootViewController?.showAlert(
title: "error".localized,
message: error.localizedDescription,
onOk: { [weak self] in self?.proceed() }
)
}
}