diff --git a/Loop.xcodeproj/project.pbxproj b/Loop.xcodeproj/project.pbxproj index f032694a9e..803e6148e0 100644 --- a/Loop.xcodeproj/project.pbxproj +++ b/Loop.xcodeproj/project.pbxproj @@ -470,23 +470,18 @@ 43757D131C06F26C00910CB9 /* Models */ = { isa = PBXGroup; children = ( + 43880F961D9D8052009061A8 /* ServiceAuthentication */, 43DE92601C555C26001FFDE1 /* AbsorptionTimeType+CarbKit.swift */, - 438849EB1D29EC34003B3F23 /* AmplitudeService.swift */, 4331E0791C85650D00FBE832 /* ChartAxisValueDoubleLog.swift */, 43F41C321D3A17AA00C11ED6 /* ChartAxisValueDoubleUnit.swift */, 43E397A21D56B9E40028E321 /* Glucose.swift */, 4D5B7A4A1D457CCA00796CA9 /* GlucoseG4.swift */, 436FACED1D0BA636004E2427 /* InsulinDataSource.swift */, 436A0DA41D236A2A00104B24 /* LoopError.swift */, - 438849ED1D2A1EBB003B3F23 /* MLabService.swift */, 430DA58F1D4B0E4C0097D1CA /* MySentryPumpStatusMessageBody.swift */, - 438849E91D297CB6003B3F23 /* NightscoutService.swift */, 438D42F81D7C88BC003244B0 /* PredictionInputEffect.swift */, 43EA28611D517E42001BC233 /* SensorDisplayable.swift */, - 437CCADF1D285C7B0075D2C3 /* ServiceAuthentication.swift */, - 434F54601D28859B002A9274 /* ServiceCredential.swift */, 43C418B41CE0575200405B6A /* ShareGlucose+GlucoseKit.swift */, - 434F545E1D288345002A9274 /* ShareService.swift */, 4328E0311CFC068900E199AA /* WatchContext+LoopKit.swift */, ); path = Models; @@ -536,6 +531,19 @@ path = Loop; sourceTree = ""; }; + 43880F961D9D8052009061A8 /* ServiceAuthentication */ = { + isa = PBXGroup; + children = ( + 438849EB1D29EC34003B3F23 /* AmplitudeService.swift */, + 438849ED1D2A1EBB003B3F23 /* MLabService.swift */, + 438849E91D297CB6003B3F23 /* NightscoutService.swift */, + 437CCADF1D285C7B0075D2C3 /* ServiceAuthentication.swift */, + 434F54601D28859B002A9274 /* ServiceCredential.swift */, + 434F545E1D288345002A9274 /* ShareService.swift */, + ); + path = ServiceAuthentication; + sourceTree = ""; + }; 43A943731B926B7B0051FA24 /* WatchApp */ = { isa = PBXGroup; children = ( diff --git a/Loop/Models/AmplitudeService.swift b/Loop/Models/ServiceAuthentication/AmplitudeService.swift similarity index 95% rename from Loop/Models/AmplitudeService.swift rename to Loop/Models/ServiceAuthentication/AmplitudeService.swift index 5e7cf86421..f2712df54b 100644 --- a/Loop/Models/AmplitudeService.swift +++ b/Loop/Models/ServiceAuthentication/AmplitudeService.swift @@ -35,10 +35,11 @@ struct AmplitudeService: ServiceAuthentication { return credentials[0].value } - var isAuthorized: Bool = false + var isAuthorized: Bool = true mutating func verify(_ completion: @escaping (_ success: Bool, _ error: Error?) -> Void) { guard let APIKey = APIKey else { + isAuthorized = false completion(false, nil) return } diff --git a/Loop/Models/MLabService.swift b/Loop/Models/ServiceAuthentication/MLabService.swift similarity index 98% rename from Loop/Models/MLabService.swift rename to Loop/Models/ServiceAuthentication/MLabService.swift index 7776611757..174f205b1e 100644 --- a/Loop/Models/MLabService.swift +++ b/Loop/Models/ServiceAuthentication/MLabService.swift @@ -62,7 +62,7 @@ struct MLabService: ServiceAuthentication { error = LoopError.connectionError } - completion(error == nil, error) + completion(true, error) }).resume() } diff --git a/Loop/Models/NightscoutService.swift b/Loop/Models/ServiceAuthentication/NightscoutService.swift similarity index 92% rename from Loop/Models/NightscoutService.swift rename to Loop/Models/ServiceAuthentication/NightscoutService.swift index 6b58b6cb04..bb649501ad 100644 --- a/Loop/Models/NightscoutService.swift +++ b/Loop/Models/ServiceAuthentication/NightscoutService.swift @@ -58,21 +58,18 @@ struct NightscoutService: ServiceAuthentication { return credentials[1].value } - var isAuthorized: Bool = false + var isAuthorized: Bool = true mutating func verify(_ completion: @escaping (_ success: Bool, _ error: Error?) -> Void) { guard let siteURL = siteURL, let APISecret = APISecret else { + isAuthorized = false completion(false, nil) return } let uploader = NightscoutUploader(siteURL: siteURL, APISecret: APISecret) uploader.checkAuth { (error) in - if let error = error { - completion(false, error) - } else { - completion(true, nil) - } + completion(true, error) } self.uploader = uploader } diff --git a/Loop/Models/ServiceAuthentication.swift b/Loop/Models/ServiceAuthentication/ServiceAuthentication.swift similarity index 100% rename from Loop/Models/ServiceAuthentication.swift rename to Loop/Models/ServiceAuthentication/ServiceAuthentication.swift diff --git a/Loop/Models/ServiceCredential.swift b/Loop/Models/ServiceAuthentication/ServiceCredential.swift similarity index 100% rename from Loop/Models/ServiceCredential.swift rename to Loop/Models/ServiceAuthentication/ServiceCredential.swift diff --git a/Loop/Models/ShareService.swift b/Loop/Models/ServiceAuthentication/ShareService.swift similarity index 100% rename from Loop/Models/ShareService.swift rename to Loop/Models/ServiceAuthentication/ShareService.swift diff --git a/Loop/View Controllers/AuthenticationViewController.swift b/Loop/View Controllers/AuthenticationViewController.swift index 9bbcae38e8..adc690fd72 100644 --- a/Loop/View Controllers/AuthenticationViewController.swift +++ b/Loop/View Controllers/AuthenticationViewController.swift @@ -37,13 +37,13 @@ final class AuthenticationViewController: UITableViewC self.navigationItem.hidesBackButton = false }) + if let error = error { + self.presentAlertController(with: error) + } + if success { self.state = .authorized } else { - if let error = error { - self.presentAlertController(with: error) - } - self.state = .unauthorized } } @@ -179,14 +179,13 @@ final class AuthenticationViewController: UITableViewC func textFieldShouldReturn(_ textField: UITextField) -> Bool { if textField.returnKeyType == .done { textField.resignFirstResponder() + validate() } else { let point = tableView.convert(textField.frame.origin, from: textField.superview) if let indexPath = tableView.indexPathForRow(at: point), let cell = tableView.cellForRow(at: IndexPath(row: indexPath.row + 1, section: indexPath.section)) as? AuthenticationTableViewCell { cell.textField.becomeFirstResponder() - - validate() } }