@@ -23,7 +23,6 @@ class SignupViewController: BaseViewController {
23
23
case upgrade( active: [ Subscription . PlanType ] )
24
24
}
25
25
26
- var enableVPNAfterSubscribe = true
27
26
var mode = Mode . newSubscription
28
27
29
28
@IBOutlet var monthlyPlanContainer : UIView !
@@ -175,61 +174,59 @@ class SignupViewController: BaseViewController {
175
174
if let presentingViewController = self . parentVC as? AccountViewController {
176
175
presentingViewController. reloadTable ( )
177
176
}
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
197
200
}
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) " )
208
205
}
209
206
}
210
207
}
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
222
225
}
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) " )
233
230
}
234
231
}
235
232
}
0 commit comments