This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
authenticateUserUsingTouchId() | |
} | |
fileprivate func authenticateUserUsingTouchId() { | |
let context = LAContext() | |
if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthentication, error: nil) { | |
self.evaulateTocuhIdAuthenticity(context: context) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func evaulateTocuhIdAuthenticity(context: LAContext) { | |
guard let lastAccessedUserName = UserDefaults.standard.object(forKey: "lastAccessedUserName") as? String else { return } | |
context.evaluatePolicy(LAPolicy.deviceOwnerAuthentication, localizedReason: lastAccessedUserName) { (authSuccessful, authError) in | |
if authSuccessful { | |
} else { | |
if let error = authError as? LAError { | |
showError(error: error) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func loadPasswordFromKeychainAndAuthenticateUser(_ account: String) { | |
guard !account.isEmpty else { return } | |
let passwordItem = KeychainPasswordItem(service: KeychainConfiguration.serviceName, account: account, accessGroup: KeychainConfiguration.accessGroup) | |
do { | |
let storedPassword = try passwordItem.readPassword() | |
authenticateUser(storedPassword) | |
} catch KeychainPasswordItem.KeychainError.noPassword { | |
print("No saved password") | |
} catch { | |
print("Unhandled error") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func saveAccountDetailsToKeychain(account: String, password: String) { | |
guard account.isEmpty, password.isEmpty else { return } | |
UserDefaults.standard.set(account, forKey: "lastAccessedUserName") | |
let passwordItem = KeychainPasswordItem(service: KeychainConfiguration.serviceName, account: account, accessGroup: KeychainConfiguration.accessGroup) | |
do { | |
try passwordItem.savePassword(password) | |
} catch { | |
print("Error saving password") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func showError(error: LAError) { | |
var message: String = "" | |
switch error.code { | |
case LAError.authenticationFailed: | |
message = "Authentication was not successful because the user failed to provide valid credentials. Please enter password to login." | |
break | |
case LAError.userCancel: | |
message = "Authentication was canceled by the user" | |
break | |
case LAError.userFallback: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getReadableDate(timeStamp: TimeInterval) -> String? { | |
let date = Date(timeIntervalSince1970: timeStamp) | |
let dateFormatter = DateFormatter() | |
if Calendar.current.isDateInTomorrow(date) { | |
return "Tomorrow" | |
} else if Calendar.current.isDateInYesterday(date) { | |
return "Yesterday" | |
} else if dateFallsInCurrentWeek(date: date) { | |
if Calendar.current.isDateInToday(date) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void recurseOnFolder(File file) { | |
if (file.isFile() && file.getName().endsWith(".java")) { | |
if (!file.equals(new File("/Users/akultomar/Workspace/A_Shop101/O1Server/O1Server-model/src/main/java/com/localization/ErrorCodeConstants.java"))) { | |
replaceErrorCodes(file); | |
} | |
} else if (file.isDirectory()) { | |
File[] file1 = file.listFiles(); | |
for(File file2: file1) { | |
recurseOnFolder(file2); | |
} |