From cd8055a14119266f6d8432caab918a8e02f4d364 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 2 Oct 2020 03:50:25 +0200 Subject: [PATCH] Extracted methods for each authentication type --- .../Security/AuthenticationService.swift | 16 +++++++++++++++- .../ui/dialogs/ProtectAppSettingsDialog.swift | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift b/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift index 2b50a3ce..db36067f 100644 --- a/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift +++ b/ui/BankingiOSApp/BankingiOSApp/Security/AuthenticationService.swift @@ -51,7 +51,21 @@ class AuthenticationService { } - func setAuthenticationType(_ type: AuthenticationType) { + func setAuthenticationMethodToPassword(_ newPassword: String) { + setAuthenticationType(.password) + + setLoginPassword(newPassword) + } + + func setAuthenticationMethodToBiometric() { + setAuthenticationType(.biometric) + } + + func removeAppProtection() { + setAuthenticationType(.none) + } + + private func setAuthenticationType(_ type: AuthenticationType) { if needsPasswordToUnlockApp { deleteLoginPassword() } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift index fc2bb21d..0b1d50d8 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/ProtectAppSettingsDialog.swift @@ -193,13 +193,13 @@ struct ProtectAppSettingsDialog: View { private func setAuthenticationType() { if isFaceIDSelected || isTouchIDSelected { - authenticationService.setAuthenticationType(.biometric) + authenticationService.setAuthenticationMethodToBiometric() } else if isPasswordSelected { - authenticationService.setAuthenticationTypeToPassword(newPassword) + authenticationService.setAuthenticationMethodToPassword(newPassword) } else if isNoAppProtectionSelected { - authenticationService.setAuthenticationType(.none) + authenticationService.removeAppProtection() } presentation.wrappedValue.dismiss()