1

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/iOS Commented Jan 30, 2015 at 17:38
  • 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. Commented Jan 30, 2015 at 21:08
  • 1
    Let me know if this ended up as the answer for you and I will put it into an answer :) Commented Jan 30, 2015 at 21:11

3 Answers 3

2

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 {
    
                           }
                       }];
      }
    
Sign up to request clarification or add additional context in comments.

Comments

0

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.

7 Comments

So one user creates an account for another user and then sends an invite (to an e-mail address) ?
That should work. So I would create essentially a User2 class with users waiting to signIn/Register, then I check against that for if (currentUser) . I believe anonymous users are generated after first ` [PFuser currentuser] ` save method. Background cleanup may be necessary.
Sorry, 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.
Ok, so you can create a user with the phone# for the username and password and then find that user again later and replace the username and password and set the e-mail. You will needs to ask for the phone# they were invited with as part of the signup somehow...
Yes, that is setup to your description. But [PFuser new] saveInBackground] crashes the app. Even if I don't save a username/password.
|
0

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.

5 Comments

I would not recommend that.
@benjaminhallock Why is that? It works well for my use case, which is an admin creating sub-users.
Because I invented a better way.
That comes off a bit smug. While your way might be better for your specific use, I thought it was a interesting approach to add to the conversation for others.
Your way involved caching a private password in an unencrypted file system and potential never destroying the instance of the password, which could easily be read if someone was debugging the program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.