Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -536,6 +531,19 @@
path = Loop;
sourceTree = "<group>";
};
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 = "<group>";
};
43A943731B926B7B0051FA24 /* WatchApp */ = {
isa = PBXGroup;
children = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct MLabService: ServiceAuthentication {
error = LoopError.connectionError
}

completion(error == nil, error)
completion(true, error)
}).resume()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 5 additions & 6 deletions Loop/View Controllers/AuthenticationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ final class AuthenticationViewController<T: ServiceAuthentication>: 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
}
}
Expand Down Expand Up @@ -179,14 +179,13 @@ final class AuthenticationViewController<T: ServiceAuthentication>: 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()
}
}

Expand Down