Skip to content

Commit 5597e76

Browse files
committed
Always enable VPN after successful subscription
1 parent 1e83da4 commit 5597e76

File tree

3 files changed

+48
-55
lines changed

3 files changed

+48
-55
lines changed

LockdowniOS/AccountVC.swift

-2
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,8 @@ final class AccountViewController: BaseViewController, Loadable {
485485
vc.parentVC = self
486486
if activePlans.isEmpty {
487487
vc.mode = .newSubscription
488-
vc.enableVPNAfterSubscribe = true
489488
} else {
490489
vc.mode = .upgrade(active: activePlans)
491-
vc.enableVPNAfterSubscribe = true
492490
}
493491
}
494492
default:

LockdowniOS/HomeViewController.swift

-2
Original file line numberDiff line numberDiff line change
@@ -747,10 +747,8 @@ class HomeViewController: BaseViewController, AwesomeSpotlightViewDelegate, Load
747747
if let vc = segue.destination as? SignupViewController {
748748
if activePlans.isEmpty {
749749
vc.mode = .newSubscription
750-
vc.enableVPNAfterSubscribe = true
751750
} else {
752751
vc.mode = .upgrade(active: activePlans)
753-
vc.enableVPNAfterSubscribe = true
754752
}
755753
}
756754
default:

LockdowniOS/SignupViewController.swift

+48-51
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class SignupViewController: BaseViewController {
2323
case upgrade(active: [Subscription.PlanType])
2424
}
2525

26-
var enableVPNAfterSubscribe = true
2726
var mode = Mode.newSubscription
2827

2928
@IBOutlet var monthlyPlanContainer: UIView!
@@ -175,61 +174,59 @@ class SignupViewController: BaseViewController {
175174
if let presentingViewController = self.parentVC as? AccountViewController {
176175
presentingViewController.reloadTable()
177176
}
178-
if self.enableVPNAfterSubscribe {
179-
// force refresh receipt, and sync with email if it exists, activate VPNte
180-
if let apiCredentials = getAPICredentials(), getAPICredentialsConfirmed() == true {
181-
DDLogInfo("purchase complete: syncing with confirmed email")
182-
firstly {
183-
try Client.signInWithEmail(email: apiCredentials.email, password: apiCredentials.password)
184-
}
185-
.then { (signin: SignIn) -> Promise<SubscriptionEvent> in
186-
DDLogInfo("purchase complete: signin result: \(signin)")
187-
return try Client.subscriptionEvent(forceRefresh: true)
188-
}
189-
.then { (result: SubscriptionEvent) -> Promise<GetKey> in
190-
DDLogInfo("purchase complete: subscriptionevent result: \(result)")
191-
return try Client.getKey()
192-
}
193-
.done { (getKey: GetKey) in
194-
try setVPNCredentials(id: getKey.id, keyBase64: getKey.b64)
195-
DDLogInfo("purchase complete: setting VPN creds with ID: \(getKey.id)")
196-
VPNController.shared.setEnabled(true)
177+
// force refresh receipt, and sync with email if it exists, activate VPNte
178+
if let apiCredentials = getAPICredentials(), getAPICredentialsConfirmed() == true {
179+
DDLogInfo("purchase complete: syncing with confirmed email")
180+
firstly {
181+
try Client.signInWithEmail(email: apiCredentials.email, password: apiCredentials.password)
182+
}
183+
.then { (signin: SignIn) -> Promise<SubscriptionEvent> in
184+
DDLogInfo("purchase complete: signin result: \(signin)")
185+
return try Client.subscriptionEvent(forceRefresh: true)
186+
}
187+
.then { (result: SubscriptionEvent) -> Promise<GetKey> in
188+
DDLogInfo("purchase complete: subscriptionevent result: \(result)")
189+
return try Client.getKey()
190+
}
191+
.done { (getKey: GetKey) in
192+
try setVPNCredentials(id: getKey.id, keyBase64: getKey.b64)
193+
DDLogInfo("purchase complete: setting VPN creds with ID: \(getKey.id)")
194+
VPNController.shared.setEnabled(true)
195+
}
196+
.catch { error in
197+
DDLogError("purchase complete: Error: \(error)")
198+
if (self.popupErrorAsNSURLError("Error activating Secure Tunnel: \(error)")) {
199+
return
197200
}
198-
.catch { error in
199-
DDLogError("purchase complete: Error: \(error)")
200-
if (self.popupErrorAsNSURLError("Error activating Secure Tunnel: \(error)")) {
201-
return
202-
}
203-
else if let apiError = error as? ApiError {
204-
switch apiError.code {
205-
default:
206-
_ = self.popupErrorAsApiError("API Error activating Secure Tunnel: \(error)")
207-
}
201+
else if let apiError = error as? ApiError {
202+
switch apiError.code {
203+
default:
204+
_ = self.popupErrorAsApiError("API Error activating Secure Tunnel: \(error)")
208205
}
209206
}
210207
}
211-
else {
212-
firstly {
213-
try Client.signIn(forceRefresh: true) // this will fetch and set latest receipt, then submit to API to get cookie
214-
}
215-
.then { (signin: SignIn) -> Promise<GetKey> in
216-
// TODO: don't always do this -- if we already have a key, then only do it once per day max
217-
try Client.getKey()
218-
}
219-
.done { (getKey: GetKey) in
220-
try setVPNCredentials(id: getKey.id, keyBase64: getKey.b64)
221-
VPNController.shared.setEnabled(true)
208+
}
209+
else {
210+
firstly {
211+
try Client.signIn(forceRefresh: true) // this will fetch and set latest receipt, then submit to API to get cookie
212+
}
213+
.then { (signin: SignIn) -> Promise<GetKey> in
214+
// TODO: don't always do this -- if we already have a key, then only do it once per day max
215+
try Client.getKey()
216+
}
217+
.done { (getKey: GetKey) in
218+
try setVPNCredentials(id: getKey.id, keyBase64: getKey.b64)
219+
VPNController.shared.setEnabled(true)
220+
}
221+
.catch { error in
222+
DDLogError("purchase complete - no email: Error: \(error)")
223+
if (self.popupErrorAsNSURLError("Error activating Secure Tunnel: \(error)")) {
224+
return
222225
}
223-
.catch { error in
224-
DDLogError("purchase complete - no email: Error: \(error)")
225-
if (self.popupErrorAsNSURLError("Error activating Secure Tunnel: \(error)")) {
226-
return
227-
}
228-
else if let apiError = error as? ApiError {
229-
switch apiError.code {
230-
default:
231-
_ = self.popupErrorAsApiError("API Error activating Secure Tunnel: \(error)")
232-
}
226+
else if let apiError = error as? ApiError {
227+
switch apiError.code {
228+
default:
229+
_ = self.popupErrorAsApiError("API Error activating Secure Tunnel: \(error)")
233230
}
234231
}
235232
}

0 commit comments

Comments
 (0)