diff --git a/Parse/Internal/User/PFUserPrivate.h b/Parse/Internal/User/PFUserPrivate.h index f8da3d10f..123ff6c96 100644 --- a/Parse/Internal/User/PFUserPrivate.h +++ b/Parse/Internal/User/PFUserPrivate.h @@ -31,8 +31,6 @@ extern NSString *const PFUserCurrentUserKeychainItemName; - (void)synchronizeAllAuthData; -- (void)checkSignUpParams; - - (BFTask *)_handleServiceLoginCommandResult:(PFCommandResult *)result; - (void)synchronizeAuthDataWithAuthType:(NSString *)authType; diff --git a/Parse/PFUser.m b/Parse/PFUser.m index cc2cd7a01..007c72e84 100644 --- a/Parse/PFUser.m +++ b/Parse/PFUser.m @@ -121,13 +121,26 @@ - (void)_checkSaveParametersWithCurrentUser:(PFUser *)currentUser { } // Checks the properties on the object before signUp. -- (void)checkSignUpParams { - @synchronized ([self lock]) { - PFConsistencyAssert(self.username, @"Cannot sign up without a username."); - PFConsistencyAssert(self.password, @"Cannot sign up without a password."); - - PFConsistencyAssert([self isDirty:NO] && !self.objectId, @"Cannot sign up an existing user."); - } +- (BFTask *)_validateSignUpAsync { + return [BFTask taskFromExecutor:[BFExecutor defaultExecutor] withBlock:^id{ + NSError *error = nil; + @synchronized (self.lock) { + if (!self.username) { + error = [PFErrorUtilities errorWithCode:kPFErrorUsernameMissing + message:@"Cannot sign up without a username."]; + } else if (!self.password) { + error = [PFErrorUtilities errorWithCode:kPFErrorUserPasswordMissing + message:@"Cannot sign up without a password."]; + } else if (![self isDirty:NO] || self.objectId) { + error = [PFErrorUtilities errorWithCode:kPFErrorUsernameTaken + message:@"Cannot sign up an existing user."]; + } + } + if (error) { + return [BFTask taskWithError:error]; + } + return nil; + }]; } - (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes @@ -444,7 +457,7 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait { // Otherwise, return an error NSError *error = [PFErrorUtilities errorWithCode:kPFErrorUsernameTaken - message:@"Cannot sign up a user that has already signed up."]; + message:@"Cannot sign up a user that has already signed up."]; return [BFTask taskWithError:error]; } @@ -452,12 +465,11 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait { // If there is a signUp or save already in progress, don't allow another one to start. if ([self _hasOutstandingOperations]) { NSError *error = [PFErrorUtilities errorWithCode:kPFErrorUsernameTaken - message:@"Cannot sign up a user that is already signing up."]; + message:@"Cannot sign up a user that is already signing up."]; return [BFTask taskWithError:error]; } - return [BFTask taskFromExecutor:[BFExecutor immediateExecutor] withBlock:^id{ - [self checkSignUpParams]; + return [[self _validateSignUpAsync] continueWithSuccessBlock:^id(BFTask *task) { if (currentUser && [PFAnonymousUtils isLinkedWithUser:currentUser]) { // self doesn't have any outstanding saves, so we can safely merge its operations // into the current user. @@ -1160,7 +1172,6 @@ - (void)signUpInBackgroundWithBlock:(PFBooleanResultBlock)block { return; } } - [self checkSignUpParams]; [[self signUpInBackground] thenCallBackOnMainThreadWithBoolValueAsync:block]; } }