Skip to content

Commit

Permalink
Merge pull request #471 from PermanentOrg/feature/VSP-1477-2FA-Verifi…
Browse files Browse the repository at this point in the history
…cation-Disabled-Status

VSP-1508 [IOS] Warning icon should appear only when 2FA is disabled
  • Loading branch information
luciancerbu-vsp authored Dec 17, 2024
2 parents 5788499 + 5587bee commit f757a47
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions Permanent/Common/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ extension Constants.Keys.StorageKeys {
static let requestPAAccess = "requestPAAccess"
static let requestLinkAccess = "requestLinkAccess"
static let biometricsAuthEnabled = "biometricsAuthOffEnabledKey"
static let twoFactorAuthEnabled = "twoFactorAuthEnabledKey"
static let fcmPushTokenKey = "fcmPushTokenKey"
static let modelVersion = "modelVersion"
static let minAppVersion = "minAppVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct TwoStepVerificationView: View {
}
.frame(maxWidth: .infinity)
HStack {
Text("\(method.type.displayName == TwoFactorMethod.MethodType.sms.displayName ? "+1 " : "")\(method.value)")
Text("\(method.value)")
.textStyle(UsualSmallXRegularTextStyle())
.foregroundColor(Color(red: 0.35, green: 0.37, blue: 0.5))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class LoginViewModel: ObservableObject {
AuthenticationManager.shared.login(withUsername: email, password: password) { status in
switch status {
case .success, .mfaToken, .unknown:
PreferencesManager.shared.removeValue(forKey: Constants.Keys.StorageKeys.twoFactorAuthEnabled)
handler(status)

case .error(message: _):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class SettingsScreenViewModel: ObservableObject {
@Published var isLoading: Bool = false
@Published var loggedOut: Bool = false

@Published var twoFactorAuthenticationEnabled: Bool? = nil
@Published var isLoading2FAStatus: Bool = false
@Published var twoFactorMethods: [TwoFactorMethod] = []

init() {
getAccountInfo { error in
if error != nil {
Expand All @@ -35,6 +39,11 @@ class SettingsScreenViewModel: ObservableObject {
self.getCurrentArchiveThumbnail()
}
}
if let twoFactorStatus: Bool = PreferencesManager.shared.getValue(forKey: Constants.Keys.StorageKeys.twoFactorAuthEnabled) {
twoFactorAuthenticationEnabled = twoFactorStatus
} else {
getTwoFAStatus()
}
}

func getAccountInfo(_ completionBlock: @escaping ((Error?) -> Void) ) {
Expand Down Expand Up @@ -69,6 +78,43 @@ class SettingsScreenViewModel: ObservableObject {
}
}

func getTwoFAStatus() {
let operation = APIOperation(AuthenticationEndpoint.getIDPUser)
isLoading2FAStatus = true
operation.execute(in: APIRequestDispatcher()) { [weak self] result in
DispatchQueue.main.async {
self?.isLoading2FAStatus = false
switch result {
case .json(let response, _):
guard let methods: [IDPUserMethodModel] = JSONHelper.convertToModel(from: response) else {
PreferencesManager.shared.set(false, forKey: Constants.Keys.StorageKeys.twoFactorAuthEnabled)
self?.twoFactorAuthenticationEnabled = false
return
}

// Convert IDPUserMethodModel to TwoFactorMethod
self?.twoFactorMethods = methods.map { method in
TwoFactorMethod(methodId: method.methodId,
method: method.method,
value: method.value)
}

// If we have any methods, 2FA is enabled
PreferencesManager.shared.set(!methods.isEmpty, forKey: Constants.Keys.StorageKeys.twoFactorAuthEnabled)
self?.twoFactorAuthenticationEnabled = !methods.isEmpty

case .error:
PreferencesManager.shared.set(false, forKey: Constants.Keys.StorageKeys.twoFactorAuthEnabled)
self?.twoFactorAuthenticationEnabled = false

default:
PreferencesManager.shared.set(false, forKey: Constants.Keys.StorageKeys.twoFactorAuthEnabled)
self?.twoFactorAuthenticationEnabled = false
}
}
}
}

func getAccountDetails() {
guard let accountData = accountData else { return }

Expand Down Expand Up @@ -145,6 +191,7 @@ class SettingsScreenViewModel: ObservableObject {
if model.isSuccessful == true {
handler(.success)
EventsManager.resetUser()
PreferencesManager.shared.removeValue(forKey: Constants.Keys.StorageKeys.twoFactorAuthEnabled)
} else {
handler(.error(message: .errorMessage))
}
Expand Down
2 changes: 1 addition & 1 deletion Permanent/Modules/SideMenus/Views/SettingsScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct SettingsScreenView: View {
Button {
settingsRouter.navigate(to: .loginAndSecurity, router: settingsRouter)
} label: {
CustomSimpleListItemView(image: Image(.securitySettings), titleText: "Login & Security", notificationIcon: true)
CustomSimpleListItemView(image: Image(.securitySettings), titleText: "Login & Security", notificationIcon: !(viewModel.twoFactorAuthenticationEnabled == true)&&(viewModel.isLoading2FAStatus == false))
}
Button {
settingsRouter.navigate(to: .legacyPlanning, router: settingsRouter)
Expand Down

0 comments on commit f757a47

Please sign in to comment.