Skip to content

Commit

Permalink
Settings page layout moved to a SwiftUI view.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensutbult committed Aug 29, 2024
1 parent c6dda52 commit d0f4140
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 64 deletions.
4 changes: 4 additions & 0 deletions Authenticator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
B4B1711827DF8C48002A62DE /* ScanAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4B1711727DF8C48002A62DE /* ScanAccountView.swift */; };
B4BB02D92C80987B00B72904 /* SettingsButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4BB02D82C80987B00B72904 /* SettingsButton.swift */; };
B4BB02DA2C809BE800B72904 /* NFCSettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51AFD4D32716FC78008F2630 /* NFCSettingsController.swift */; };
B4BB02DC2C80A09500B72904 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4BB02DB2C80A09500B72904 /* SettingsView.swift */; };
B4C93E60299D156C00C2A8B8 /* ErrorAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4C93E5F299D156C00C2A8B8 /* ErrorAlertView.swift */; };
B4C93E63299FB51A00C2A8B8 /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4C93E62299FB51A00C2A8B8 /* Account.swift */; };
B4C93E65299FC67800C2A8B8 /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4C93E64299FC67800C2A8B8 /* View+Extensions.swift */; };
Expand Down Expand Up @@ -263,6 +264,7 @@
B4901B072BD91DA60092E7A2 /* InfoPlist.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = InfoPlist.xcstrings; sourceTree = "<group>"; };
B4B1711727DF8C48002A62DE /* ScanAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanAccountView.swift; sourceTree = "<group>"; };
B4BB02D82C80987B00B72904 /* SettingsButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsButton.swift; sourceTree = "<group>"; };
B4BB02DB2C80A09500B72904 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
B4C93E5F299D156C00C2A8B8 /* ErrorAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorAlertView.swift; sourceTree = "<group>"; };
B4C93E62299FB51A00C2A8B8 /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; };
B4C93E64299FC67800C2A8B8 /* View+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -430,6 +432,7 @@
B452EC3C2A264A620045E5D9 /* ToastView.swift */,
B452EC432A2A06940045E5D9 /* ToastPresenter.swift */,
B4BB02D82C80987B00B72904 /* SettingsButton.swift */,
B4BB02DB2C80A09500B72904 /* SettingsView.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -752,6 +755,7 @@
515542852656A30B00B19C59 /* UIButton+Extensions.swift in Sources */,
51BBE37F273982D700DA47CC /* YKFOATHSession+Extensions.swift in Sources */,
B44E5EB32C777F22007ABB79 /* OATHPasswordViewModel.swift in Sources */,
B4BB02DC2C80A09500B72904 /* SettingsView.swift in Sources */,
B44E5E812C74BE67007ABB79 /* OATHResetView.swift in Sources */,
B411242F29D423A300D58001 /* ListStatusView.swift in Sources */,
816C684823430F8E00209342 /* SecureStoreQueryable.swift in Sources */,
Expand Down
9 changes: 6 additions & 3 deletions Authenticator/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,9 @@
}
}
}
},
"For additional security and to prevent unauthorized access the YubiKey can be password protected." : {

},
"Incorrect password. Re-enter password." : {
"comment" : "OATH password entry retry",
Expand Down Expand Up @@ -1004,9 +1007,6 @@
}
}
}
},
"Manage OATH passwords" : {

},
"Menu" : {
"localizations" : {
Expand Down Expand Up @@ -1279,6 +1279,9 @@
}
}
}
},
"OATH password protection" : {

},
"OATH passwords" : {

Expand Down
41 changes: 41 additions & 0 deletions Authenticator/UI/Helpers/SettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// SettingsView.swift
// Authenticator
//
// Created by Jens Utbult on 2024-08-29.
// Copyright © 2024 Yubico. All rights reserved.
//

import SwiftUI

struct SettingsView<Image: View, Content: View, Buttons: View>: View {

var image: Image? = nil
@ViewBuilder var content: () -> Content
@ViewBuilder var buttons: () -> Buttons

var body: some View {
VStack {
VStack(spacing: 0) {
VStack(spacing: 10) {
if let image {
image
.font(.system(size:50.0))
.bold()
.foregroundColor(Color(.yubiBlue))
.accessibilityHidden(true)
}
content()
}
.padding(30)
buttons()
}
.frame(maxWidth: .infinity)
.background(Color(.secondarySystemGroupedBackground))
.clipShape(RoundedRectangle(cornerRadius: 15, style: .continuous))
.padding(20)
Spacer()
}
.background(Color(.systemGroupedBackground))
}
}
59 changes: 20 additions & 39 deletions Authenticator/UI/YubiKeyConfiguration/OATHPasswordView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,29 @@ struct OATHPasswordView: View {
}

var body: some View {
VStack {
VStack(spacing: 0) {
VStack(spacing: 10) {
Image(systemName: "key")
.font(.system(size:50.0))
.bold()
.foregroundColor(Color(.yubiBlue))
.rotationEffect(Angle(degrees: 90))
.accessibilityHidden(true)
Text("Manage OATH passwords").font(.headline)
Text("Reset all accounts stored on YubiKey, make sure they are not in use anywhere before doing this.")
.font(.callout)
.multilineTextAlignment(.center)
}
.padding(.horizontal, 30)
.padding(.bottom, 30)
if showSetButton {
SettingsButton("Set password") {
presentSetPassword.toggle()
}.disabled(areButtonsDisabled())
}
if showChangeButton {
SettingsButton("Change password") {
presentChangePassword.toggle()
}.disabled(areButtonsDisabled())
}
if showRemoveButton {
SettingsButton("Remove password") {
presentRemovePassword.toggle()
}.disabled(areButtonsDisabled())
}
SettingsView(image: Image(systemName: "key")) {
Text("OATH password protection").font(.headline)
Text("For additional security and to prevent unauthorized access the YubiKey can be password protected.")
.font(.callout)
.multilineTextAlignment(.center)
} buttons: {
if showSetButton {
SettingsButton("Set password") {
presentSetPassword.toggle()
}.disabled(areButtonsDisabled())
}
if showChangeButton {
SettingsButton("Change password") {
presentChangePassword.toggle()
}.disabled(areButtonsDisabled())
}
if showRemoveButton {
SettingsButton("Remove password") {
presentRemovePassword.toggle()
}.disabled(areButtonsDisabled())
}
.frame(maxWidth: .infinity)
.background(Color(.secondarySystemGroupedBackground))
.clipShape(RoundedRectangle(cornerRadius: 15, style: .continuous))
.padding(20)
.opacity(model.state.isError() ? 0.5 : 1.0)
Spacer()
}
.background(Color(.systemGroupedBackground))
.navigationBarTitle(Text("OATH passwords"), displayMode: .inline)

.alert("Set password", isPresented: $presentSetPassword) {
SecureField("Password", text: $newPassword)
SecureField("Repeat new password", text: $repeatedPassword)
Expand Down
32 changes: 10 additions & 22 deletions Authenticator/UI/YubiKeyConfiguration/OATHResetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,18 @@ struct OATHResetView: View {
@State var errorMessage: String? = nil

var body: some View {
VStack {
VStack {
Image(systemName: "exclamationmark.triangle")
.font(.system(size:50.0))
.bold()
.foregroundColor(.red)
.accessibilityHidden(true)
.padding(20)
Text(keyHasBeenReset ? "YubiKey has been reset" : "Reset OATH application").font(.headline)
Text("Reset all accounts stored on YubiKey, make sure they are not in use anywhere before doing this.")
.multilineTextAlignment(.center)
.opacity(keyHasBeenReset ? 0.2 : 1.0)
SettingsButton("Reset Yubikey") {
presentConfirmAlert.toggle()
}
.disabled(keyHasBeenReset)
SettingsView(image: Image(systemName: "exclamationmark.triangle").foregroundColor(.red)) {
Text(keyHasBeenReset ? "YubiKey has been reset" : "Reset OATH application").font(.headline)
Text("Reset all accounts stored on YubiKey, make sure they are not in use anywhere before doing this.")
.multilineTextAlignment(.center)
.opacity(keyHasBeenReset ? 0.2 : 1.0)
} buttons: {
SettingsButton("Reset Yubikey") {
presentConfirmAlert.toggle()
}
.frame(maxWidth: .infinity)
.background(Color(.secondarySystemGroupedBackground))
.clipShape(RoundedRectangle(cornerRadius: 15, style: .continuous))
.padding(20)
.navigationBarTitle(Text("Reset OATH"), displayMode: .inline)
Spacer()
.disabled(keyHasBeenReset)
}
.navigationBarTitle(Text("Reset OATH"), displayMode: .inline)
.alert("Confirm OATH reset", isPresented: $presentConfirmAlert, presenting: model, actions: { model in
Button(role: .destructive) {
presentConfirmAlert.toggle()
Expand Down

0 comments on commit d0f4140

Please sign in to comment.