Added more robust app documentation. Started working on an issue where entering zero as the first number in the Distance text field causes the app to crash.
This commit is contained in:
parent
7d6643112d
commit
b6677c2053
7 changed files with 108 additions and 41 deletions
|
|
@ -13,9 +13,25 @@ import LocalAuthentication
|
|||
// the reader has a basic understanding of
|
||||
// Swift and/or SwiftUI.
|
||||
|
||||
/// The system username for the app
|
||||
/// - Note: This is not a secure way to do it
|
||||
/// or in any way good practice
|
||||
/// but this is mainly to test out `SecureField`
|
||||
let username = "admin"
|
||||
|
||||
/// The system password associated with ``username``
|
||||
///
|
||||
/// I'm thinking about hashing them, but that would take work.
|
||||
///
|
||||
/// It would be more secure though.
|
||||
/// - Note: Just as with `username` you should not define
|
||||
/// these unencrypted like they are right now.
|
||||
let password = "123"
|
||||
|
||||
/// Holds the views and login for the Docs tab in-app
|
||||
///
|
||||
/// Mostly just a long list of sections and calling views
|
||||
/// - Note: New views are best called in this `struct`
|
||||
struct DocsView: View {
|
||||
enum Field: Hashable {
|
||||
case username
|
||||
|
|
@ -46,8 +62,8 @@ struct DocsView: View {
|
|||
}
|
||||
Section(header: Text("App Information")) {
|
||||
NavigationLink("Software License", destination: LicenseView())
|
||||
Text("Version: Release Candidate 2 (1.0.0)")
|
||||
Text("Release date: 2022-06-11")
|
||||
Text("Version: Prerelease Build LVSXT10a.3")
|
||||
Text("Release date: 2022-06-14")
|
||||
Text("Start date: 2022-03-25")
|
||||
Link("Built with SwiftUI \(Image(systemName: "swift"))", destination: URL(string: "https://developer.apple.com/xcode/swiftui")!)
|
||||
}
|
||||
|
|
@ -60,21 +76,21 @@ struct DocsView: View {
|
|||
isUnlocked = false
|
||||
}
|
||||
} else {
|
||||
if !isUnlocked {
|
||||
Button("Log in with biometrics") {
|
||||
authenticate()
|
||||
}
|
||||
Button("Log in with biometrics") {
|
||||
authenticate()
|
||||
}
|
||||
SecureField("Username", text: $user)
|
||||
.keyboardType(.alphabet)
|
||||
.textContentType(.username)
|
||||
.submitLabel(.next)
|
||||
.focused($focusedField, equals: .username)
|
||||
.textContentType(.username)
|
||||
SecureField("Password", text: $pass)
|
||||
.keyboardType(.numbersAndPunctuation)
|
||||
.textContentType(.password)
|
||||
.submitLabel(.done)
|
||||
.focused($focusedField, equals: .password)
|
||||
.textContentType(.password)
|
||||
if checkPassword() {
|
||||
NavigationLink("Contacts", destination: SecretView())
|
||||
}
|
||||
|
|
@ -90,11 +106,19 @@ struct DocsView: View {
|
|||
default:
|
||||
()
|
||||
}
|
||||
if (pass == password && user == username) {
|
||||
if checkPassword() {
|
||||
isUnlocked = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Compares the `user` SecureField and the `pass` SecureField against ``username`` and ``password``
|
||||
///
|
||||
/// - Note: come back to this
|
||||
///
|
||||
///
|
||||
/// - Returns: `true` if `user` equals `username` *and* `pass` equals `password`, `false` if one or both checks return false.
|
||||
func checkPassword() -> Bool {
|
||||
if (pass == password && user == username) {
|
||||
return true
|
||||
|
|
@ -102,11 +126,15 @@ struct DocsView: View {
|
|||
return false
|
||||
}
|
||||
}
|
||||
func checkIfUnlocked() {
|
||||
if !isUnlocked {
|
||||
authenticate()
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks wether the user can use biometrics to sign in
|
||||
/// and (if true) prompts the user to sign with either FaceID or TouchID
|
||||
/// depending on the device.
|
||||
///
|
||||
/// If the prompt was shown, and the user authenticated correctly
|
||||
/// `isUnlocked` is set to `true`
|
||||
///
|
||||
/// - Note: `authenticate()` has to be called to show the sign-in sheet
|
||||
func authenticate() {
|
||||
let context = LAContext()
|
||||
var error: NSError?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue