@@ -51,7 +51,11 @@ class SignupService {
5151 func createWPComUserWithApple( token: String ,
5252 email: String ,
5353 fullName: String ? ,
54- success: @escaping ( _ newAccount: Bool , _ existingNonSocialAccount: Bool , _ username: String , _ wpcomToken: String ) -> Void ,
54+ success: @escaping ( _ newAccount: Bool ,
55+ _ existingNonSocialAccount: Bool ,
56+ _ existing2faAccount: Bool ,
57+ _ username: String ,
58+ _ wpcomToken: String ) -> Void ,
5559 failure: @escaping ( _ error: Error ) -> Void ) {
5660 let remote = WordPressComServiceRemote ( wordPressComRestApi: anonymousAPI)
5761
@@ -68,22 +72,27 @@ class SignupService {
6872 }
6973
7074 let createdAccount = ( response ? [ ResponseKeys . createdAccount] as? Int ?? 0 ) == 1
71- success ( createdAccount, false , username, bearer_token)
75+ success ( createdAccount, false , false , username, bearer_token)
7276 } , failure: { error in
7377 if let error = ( error as NSError ? ) {
7478
75- // If an account already exists, the account email should be returned in the Error response.
76- // Extract it and return it.
77- var existingEmail = " "
78- if let errorData = error. userInfo [ WordPressComRestApi . ErrorKeyErrorData] as? [ String : String ] {
79- let emailDict = errorData. first { $0. key == WordPressComRestApi . ErrorKeyErrorDataEmail }
80- let email = emailDict? . value ?? " "
81- existingEmail = email
79+ if ( error. userInfo [ ErrorKeys . errorCode] as? String ?? " " ) == ErrorKeys . twoFactorEnabled {
80+ success ( false , true , true , " " , " " )
81+ return
8282 }
8383
84- let existingNonSocialAccount = ( error. userInfo [ ErrorKeys . errorCode] as? String ?? " " ) == ErrorKeys . existingNonSocialUser
85- if existingNonSocialAccount {
86- success ( false , true , existingEmail, " " )
84+ if ( error. userInfo [ ErrorKeys . errorCode] as? String ?? " " ) == ErrorKeys . existingNonSocialUser {
85+
86+ // If an account already exists, the account email should be returned in the Error response.
87+ // Extract it and return it.
88+ var existingEmail = " "
89+ if let errorData = error. userInfo [ WordPressComRestApi . ErrorKeyErrorData] as? [ String : String ] {
90+ let emailDict = errorData. first { $0. key == WordPressComRestApi . ErrorKeyErrorDataEmail }
91+ let email = emailDict? . value ?? " "
92+ existingEmail = email
93+ }
94+
95+ success ( false , true , false , existingEmail, " " )
8796 return
8897 }
8998 }
@@ -118,6 +127,7 @@ private extension SignupService {
118127 struct ErrorKeys {
119128 static let errorCode = " WordPressComRestApiErrorCodeKey "
120129 static let existingNonSocialUser = " user_exists "
130+ static let twoFactorEnabled = " 2FA_enabled "
121131 }
122132}
123133
0 commit comments