1
votes

It seems Parse does not let me create new users, unless the sign up block is called.

It also seems that Parse doesn't let you edit username/password unless that user is currentUser logged in.

The goal is to create a new user, save him, and when they sign up at a later point, I can recognize their previous user account, or create one if that does not exist.

Signup/Login block methods are not the answer, I do not want to change the current user.

                   PFQuery *query = [PFUser query];
                  PFUser *userAgain = (PFUser *)[query getObjectWithId:user.objectId];
                  userAgain.username = "another_username";
 // This will throw an exception, since the PFUser is not authenticated
                  [userAgain save]

P.S. Here's the elevator pitch. This is a chat app (signup w/ phone#). I want to invite users in my contacts (but not on app) to a "chatroom". So i create a user account for their phone#. When they signup, I login that previously created user (checking phone#s) , and they see my "chatroom" in their inbox.

3
could you not use an anonymous user? : parse.com/docs/ios_guide#users-anonymous/iOSJayDev
Yes! I think i will. I have to check for isVerified against the phone number txt message. Then dispose of any unwanted automatic users (if there are any). Then! I may be able to create accounts for people who aren't on the app yet.benjaminhallock
Let me know if this ended up as the answer for you and I will put it into an answer :)JayDev

3 Answers

2
votes

Okay, here's the steps I had to take.

On the Signin End

  1. Enable enableAutomaticUser for anonymous user.

  2. PFQuery for user registering to make sure his account doesn't exist based on his phoneNumber

  3. If PFQuery has an object, save this PFUser, we will login with his credentials AFTER and IF the text message verification is true.

On Signup End

  1. For each phoneNumber, make sure a user doesn't already exist. If it does, forget that phoneNumber, add the PFuser

  2. Enumerate each phoneNumber for Register using the REST API

    - (void) saveNewUserWithPhoneNumber:(NSString *)phoneNumber
     {
    NSURL *url = [NSURL URLWithString:@"https://api.parse.com/1/users"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
      [request setURL:url];
      [request setHTTPMethod:@"POST"];
     [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
     [request setValue:API KEY forHTTPHeaderField:@"X-Parse-REST-API-Key"];
     [request setValue:APP ID forHTTPHeaderField:@"X-Parse-Application-Id"];
    
    NSDictionary *dict = @{@"username":phoneNumber,@"password":phoneNumber,PF_USER_PHONENUMBER:phoneNumber, PF_USER_ISVERIFIED: @NO};
     NSError *error;
     NSData *postBody = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    [request setHTTPBody:postBody];
    
     // Send request to Parse and parse returned data
     [NSURLConnection sendAsynchronousRequest:request
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                           if (!connectionError) {
                               NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    
                               NSString *objectId = [responseDictionary valueForKey:@"objectId"];
                               [_arrayOfSelectedUsers addObject:[PFUser objectWithoutDataWithObjectId:objectId]];
                               x--;
                               //If we finished all the phone numbers, create the chatroom;
                               if (x == 0){
                                   [self actionSend];
                               }
    
                           } else {
    
                           }
                       }];
      }
    
1
votes

You could look at using enableAutomaticUser. If you add a relationship between the user and some other object in the data store then that user would be saved. I haven't tried doing it to make sure that a new anonymous user is not created before you set the e-mail and password (or request a password reset), but it should work.

You can set the e-mail and password of the user and then save it.

-1
votes

If you have cached the password of the original user, you can log back in with that user after creating the new user. It seems a bit hackish, but it worked for me.