Require credentials for providers only

Not always the case, but PIA certainly requires them. Will make it
an infrastructure option later. Only require credentials as a
configuration check, everything else has defaults.
This commit is contained in:
Davide De Rosa 2018-10-18 22:51:37 +02:00
parent 76cf7ba8d5
commit 5e0590184b
8 changed files with 20 additions and 21 deletions

View File

@ -190,10 +190,10 @@ class ServiceViewController: UIViewController, TableModelHost {
private func toggleVpnService(cell: ToggleTableViewCell) {
if cell.isOn {
guard service.canActivate(uncheckedProfile) else {
guard !service.needsCredentials(for: uncheckedProfile) else {
let alert = Macros.alert(
L10n.Service.Sections.Vpn.header,
L10n.Service.Alerts.ConfigurationNeeded.message
L10n.Service.Alerts.CredentialsNeeded.message
)
alert.addCancelAction(L10n.Global.ok) {
cell.setOn(false, animated: true)
@ -522,7 +522,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
cell.applyVPN(Theme.current, with: vpn.isEnabled ? vpn.status : nil)
cell.leftText = L10n.Service.Cells.ConnectionStatus.caption
cell.accessoryType = .none
cell.isTappable = service.canActivate(uncheckedProfile) && vpn.isEnabled
cell.isTappable = !service.needsCredentials(for: uncheckedProfile) && vpn.isEnabled
return cell
case .useProfile:

View File

@ -98,7 +98,7 @@
"service.cells.data_count.caption" = "Exchanged bytes count";
"service.cells.debug_log.caption" = "Debug log";
"service.alerts.configuration_needed.message" = "You need to finish configuration first.";
"service.alerts.credentials_needed.message" = "You need to enter account credentials first.";
"service.alerts.reconnect_vpn.message" = "Do you want to reconnect to the VPN?";
"service.alerts.trusted.no_network.message" = "You are not connected to any Wi-Fi network.";
"service.alerts.trusted.will_disconnect_trusted.message" = "By trusting this network, the VPN may be disconnected. Continue?";

View File

@ -34,7 +34,7 @@ protocol ConnectionProfile: class, EndpointDataSource {
var username: String? { get set }
var isConfigured: Bool { get }
var requiresCredentials: Bool { get }
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration
}

View File

@ -180,21 +180,20 @@ class ConnectionService: Codable {
return profile.id == activeProfileId
}
func canActivate(_ profile: ConnectionProfile) -> Bool {
return profile.isConfigured && hasCredentials(for: profile)
}
func activateProfile(_ profile: ConnectionProfile) {
activeProfileId = profile.id
}
// MARK: Credentials
func hasCredentials(for profile: ConnectionProfile) -> Bool {
guard let creds = credentials(for: profile) else {
func needsCredentials(for profile: ConnectionProfile) -> Bool {
guard profile.requiresCredentials else {
return false
}
return !creds.isEmpty
guard let creds = credentials(for: profile) else {
return true
}
return creds.isEmpty
}
func credentials(for profile: ConnectionProfile) -> Credentials? {

View File

@ -47,8 +47,8 @@ class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
var username: String?
var isConfigured: Bool {
return !parameters.endpointProtocols.isEmpty
var requiresCredentials: Bool {
return false
}
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration {

View File

@ -101,10 +101,10 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
var username: String?
var isConfigured: Bool {
return (pool != nil) && (preset != nil)
var requiresCredentials: Bool {
return true
}
func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration {
guard let pool = pool else {
throw ApplicationError.providerPool

View File

@ -423,9 +423,9 @@ internal enum L10n {
internal enum Alerts {
internal enum ConfigurationNeeded {
/// You need to finish configuration first.
internal static let message = L10n.tr("Localizable", "service.alerts.configuration_needed.message")
internal enum CredentialsNeeded {
/// You need to enter account credentials first.
internal static let message = L10n.tr("Localizable", "service.alerts.credentials_needed.message")
}
internal enum DataCount {

View File

@ -40,4 +40,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: f6888fe9e046f88d139af75dd5308916c5be8b7b
COCOAPODS: 1.6.0.beta.1
COCOAPODS: 1.6.0.beta.2