@@ -121,13 +121,26 @@ - (void)_checkSaveParametersWithCurrentUser:(PFUser *)currentUser {
121
121
}
122
122
123
123
// Checks the properties on the object before signUp.
124
- - (void )checkSignUpParams {
125
- @synchronized ([self lock ]) {
126
- PFConsistencyAssert (self.username , @" Cannot sign up without a username." );
127
- PFConsistencyAssert (self.password , @" Cannot sign up without a password." );
128
-
129
- PFConsistencyAssert ([self isDirty: NO ] && !self.objectId , @" Cannot sign up an existing user." );
130
- }
124
+ - (BFTask *)_validateSignUpAsync {
125
+ return [BFTask taskFromExecutor: [BFExecutor defaultExecutor ] withBlock: ^id {
126
+ NSError *error = nil ;
127
+ @synchronized (self.lock ) {
128
+ if (!self.username ) {
129
+ error = [PFErrorUtilities errorWithCode: kPFErrorUsernameMissing
130
+ message: @" Cannot sign up without a username." ];
131
+ } else if (!self.password ) {
132
+ error = [PFErrorUtilities errorWithCode: kPFErrorUserPasswordMissing
133
+ message: @" Cannot sign up without a password." ];
134
+ } else if (![self isDirty: NO ] || self.objectId ) {
135
+ error = [PFErrorUtilities errorWithCode: kPFErrorUsernameTaken
136
+ message: @" Cannot sign up an existing user." ];
137
+ }
138
+ }
139
+ if (error) {
140
+ return [BFTask taskWithError: error];
141
+ }
142
+ return nil ;
143
+ }];
131
144
}
132
145
133
146
- (NSMutableDictionary *)_convertToDictionaryForSaving : (PFOperationSet *)changes
@@ -444,20 +457,19 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait {
444
457
445
458
// Otherwise, return an error
446
459
NSError *error = [PFErrorUtilities errorWithCode: kPFErrorUsernameTaken
447
- message: @" Cannot sign up a user that has already signed up." ];
460
+ message: @" Cannot sign up a user that has already signed up." ];
448
461
return [BFTask taskWithError: error];
449
462
}
450
463
451
464
// If the operationSetQueue is has operation sets in it, then a save or signUp is in progress.
452
465
// If there is a signUp or save already in progress, don't allow another one to start.
453
466
if ([self _hasOutstandingOperations ]) {
454
467
NSError *error = [PFErrorUtilities errorWithCode: kPFErrorUsernameTaken
455
- message: @" Cannot sign up a user that is already signing up." ];
468
+ message: @" Cannot sign up a user that is already signing up." ];
456
469
return [BFTask taskWithError: error];
457
470
}
458
471
459
- return [BFTask taskFromExecutor: [BFExecutor immediateExecutor ] withBlock: ^id {
460
- [self checkSignUpParams ];
472
+ return [[self _validateSignUpAsync ] continueWithSuccessBlock: ^id (BFTask *task) {
461
473
if (currentUser && [PFAnonymousUtils isLinkedWithUser: currentUser]) {
462
474
// self doesn't have any outstanding saves, so we can safely merge its operations
463
475
// into the current user.
@@ -1160,7 +1172,6 @@ - (void)signUpInBackgroundWithBlock:(PFBooleanResultBlock)block {
1160
1172
return ;
1161
1173
}
1162
1174
}
1163
- [self checkSignUpParams ];
1164
1175
[[self signUpInBackground ] thenCallBackOnMainThreadWithBoolValueAsync: block];
1165
1176
}
1166
1177
}
0 commit comments