Skip to content

Replace exceptions in PFUser.signUp with errors. #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Parse/Internal/User/PFUserPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ extern NSString *const PFUserCurrentUserKeychainItemName;

- (void)synchronizeAllAuthData;

- (void)checkSignUpParams;

- (BFTask *)_handleServiceLoginCommandResult:(PFCommandResult *)result;

- (void)synchronizeAuthDataWithAuthType:(NSString *)authType;
Expand Down
35 changes: 23 additions & 12 deletions Parse/PFUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -444,20 +457,19 @@ - (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];
}

// If the operationSetQueue is has operation sets in it, then a save or signUp is in progress.
// 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.
Expand Down Expand Up @@ -1160,7 +1172,6 @@ - (void)signUpInBackgroundWithBlock:(PFBooleanResultBlock)block {
return;
}
}
[self checkSignUpParams];
[[self signUpInBackground] thenCallBackOnMainThreadWithBoolValueAsync:block];
}
}
Expand Down