The verification Procedure and making new users logic, parse.com

◇◆丶佛笑我妖孽 提交于 2020-01-17 08:03:51

问题


I am stuck at how to think when to create new anonymous users. This is how my application is setup right now.

I got three ViewControllers.

1) GetPhoneController, 2) VerificationController , 3) ViewController

GetPhoneController: is the first view where, IF the user that opened the application has no user stored meaning [PFUser currentUser]; is equal to NULL then this view will be run otherwise ViewController will execute ( the check is done in AppDelegate ). This view will just get the user's phone number in a UITextField and is sent to the next controller

VerificationController: When this view is opened a text message is sent to the user with a VerificationCode. I am using Twilio with parse. The verification code is saved in a custom field in the User object to be used later for matching the codes.( problem here u will know why later).

A check is done if the user enters the right verification code, and if the user did do that THEN i want the anonymous user to be created and move on to the next controller. Why? Cause if i create a user before he is validated then in a scenario a user might shut the application down and then a user has been created for nothing taking up extra space.

So my problem is that i try to save the verification code to a user that does not exist since i want to create it AFTER validation.

A solution for this would be awesome or even better if you have a better solution to how to make the verification logic steps better.

Also i never sign out the user since i don't want the user to login after the verification is done, also it would mean that the anonymous user would be deleted, is that bad or is that ok to use like that?

Thank you!


回答1:


If you don't want to create a user in Parse before the validation is complete, you could save the validation token to NSUserDefaults.

In the method in VerificationController that sends the verification code...

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:verificationCode forKey:@"code"];
[defaults synchronize];

Then, to check when the user enters the code, and taps a button...

- (void)userTappedCheckCodeButton:(id)sender {
  NSString *enteredCode = codeField.text;
  NSString *storedCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"code"];
  if ([enteredCode isEqualToString:storedCode]) {
    // Code matches. Create your anonymous user as the code has been verified.
  } else {
    // No code match. Tell the user, or maybe ask if they want to send the code again.
  }
}

--- Edit with new info that code generation happens server side ---

If you really don't want to create a User until they're verified and code generation happens server side, you could use create a new VerificationToken object in Parse. You can generate an identifier for the users device via [[NSUUID UUID] UUIDString], and store in in NSUserDefaults (that way, you don't need to use the advertising identifier, and it's persistent across application executions). Send in that UUID with the request to generate and send the code to the user, and save it in the verification object with your cloud code function.

On the VerificationController, just send in the code with the UUID that you've retrieved from NSUserDefaults, search for the VerificationToken object that matches that, return success, and create the anonymous user.

And finally, if you're worried about having thousands of uncompleted VerificationToken objects cluttering up Parse, just tell users they only last for 24 hours, and create a scheduled cloud code job to go and delete all VerificationToken objects that have a createdAt date older than 1 day ago, and schedule the task to run daily.



来源:https://stackoverflow.com/questions/28079184/the-verification-procedure-and-making-new-users-logic-parse-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!