|
21 | 21 |
|
22 | 22 | @interface PFUserAuthenticationController () { |
23 | 23 | dispatch_queue_t _dataAccessQueue; |
24 | | - NSMutableDictionary PF_GENERIC(NSString *, id<PFUserAuthenticationDelegate>) *_authenticationDelegates; |
| 24 | + NSMutableDictionary PF_GENERIC(NSString *, id<PFUserAuthenticationDelegate>)*_authenticationDelegates; |
25 | 25 | } |
26 | 26 |
|
27 | 27 | @end |
@@ -115,55 +115,54 @@ - (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType { |
115 | 115 |
|
116 | 116 | - (BFTask PF_GENERIC(PFUser *)*)logInUserAsyncWithAuthType:(NSString *)authType |
117 | 117 | authData:(NSDictionary PF_GENERIC(NSString *, NSString *)*)authData { |
118 | | - //TODO: (nlutsenko) Make it fully async. |
119 | | - PFUser *currentUser = [PFUser currentUser]; |
120 | | - if (currentUser && [PFAnonymousUtils isLinkedWithUser:currentUser]) { |
121 | | - if (currentUser.isLazy) { |
122 | | - PFUser *user = currentUser; |
123 | | - BFTask *resolveLaziness = nil; |
124 | | - NSDictionary *oldAnonymousData = nil; |
125 | | - @synchronized(user.lock) { |
126 | | - oldAnonymousData = user.authData[PFAnonymousUserAuthenticationType]; |
127 | | - |
128 | | - // Replace any anonymity with the new linked authData |
129 | | - [user stripAnonymity]; |
130 | | - |
131 | | - [user.authData setObject:authData forKey:authType]; |
132 | | - [user.linkedServiceNames addObject:authType]; |
133 | | - |
134 | | - resolveLaziness = [user resolveLazinessAsync:[BFTask taskWithResult:nil]]; |
135 | | - } |
136 | | - |
137 | | - return [resolveLaziness continueAsyncWithBlock:^id(BFTask *task) { |
138 | | - if (task.cancelled || task.faulted) { |
139 | | - [user.authData removeObjectForKey:authType]; |
140 | | - [user.linkedServiceNames removeObject:authType]; |
141 | | - [user restoreAnonymity:oldAnonymousData]; |
142 | | - return task; |
| 118 | + return [[self.dataSource.currentUserController getCurrentUserAsyncWithOptions:0] continueWithSuccessBlock:^id(BFTask PF_GENERIC(PFUser *)*task) { |
| 119 | + PFUser *currentUser = task.result; |
| 120 | + if (currentUser && [PFAnonymousUtils isLinkedWithUser:currentUser]) { |
| 121 | + if (currentUser.isLazy) { |
| 122 | + BFTask *resolveLaziness = nil; |
| 123 | + NSDictionary *oldAnonymousData = nil; |
| 124 | + @synchronized(currentUser.lock) { |
| 125 | + oldAnonymousData = currentUser.authData[PFAnonymousUserAuthenticationType]; |
| 126 | + |
| 127 | + // Replace any anonymity with the new linked authData |
| 128 | + [currentUser stripAnonymity]; |
| 129 | + |
| 130 | + currentUser.authData[authType] = authData; |
| 131 | + [currentUser.linkedServiceNames addObject:authType]; |
| 132 | + |
| 133 | + resolveLaziness = [currentUser resolveLazinessAsync:[BFTask taskWithResult:nil]]; |
143 | 134 | } |
144 | | - return task.result; |
145 | | - }]; |
146 | | - } else { |
147 | | - return [[currentUser linkWithAuthTypeInBackground:authType authData:authData] continueAsyncWithBlock:^id(BFTask *task) { |
148 | | - NSError *error = task.error; |
149 | | - if (error) { |
150 | | - if (error.code == kPFErrorAccountAlreadyLinked) { |
151 | | - // An account that's linked to the given authData already exists, |
152 | | - // so log in instead of trying to claim. |
153 | | - return [self.dataSource.userController logInCurrentUserAsyncWithAuthType:authType |
154 | | - authData:authData |
155 | | - revocableSession:[PFUser _isRevocableSessionEnabled]]; |
156 | | - } else { |
| 135 | + return [resolveLaziness continueWithBlock:^id(BFTask *task) { |
| 136 | + if (task.cancelled || task.faulted) { |
| 137 | + [currentUser.authData removeObjectForKey:authType]; |
| 138 | + [currentUser.linkedServiceNames removeObject:authType]; |
| 139 | + [currentUser restoreAnonymity:oldAnonymousData]; |
157 | 140 | return task; |
158 | 141 | } |
159 | | - } |
160 | | - return currentUser; |
161 | | - }]; |
| 142 | + return task.result; |
| 143 | + }]; |
| 144 | + } else { |
| 145 | + return [[currentUser linkWithAuthTypeInBackground:authType authData:authData] continueWithBlock:^id(BFTask *task) { |
| 146 | + NSError *error = task.error; |
| 147 | + if (error) { |
| 148 | + if (error.code == kPFErrorAccountAlreadyLinked) { |
| 149 | + // An account that's linked to the given authData already exists, |
| 150 | + // so log in instead of trying to claim. |
| 151 | + return [self.dataSource.userController logInCurrentUserAsyncWithAuthType:authType |
| 152 | + authData:authData |
| 153 | + revocableSession:[PFUser _isRevocableSessionEnabled]]; |
| 154 | + } else { |
| 155 | + return task; |
| 156 | + } |
| 157 | + } |
| 158 | + return currentUser; |
| 159 | + }]; |
| 160 | + } |
162 | 161 | } |
163 | | - } |
164 | | - return [self.dataSource.userController logInCurrentUserAsyncWithAuthType:authType |
165 | | - authData:authData |
166 | | - revocableSession:[PFUser _isRevocableSessionEnabled]]; |
| 162 | + return [self.dataSource.userController logInCurrentUserAsyncWithAuthType:authType |
| 163 | + authData:authData |
| 164 | + revocableSession:[PFUser _isRevocableSessionEnabled]]; |
| 165 | + }]; |
167 | 166 | } |
168 | 167 |
|
169 | 168 | @end |
0 commit comments