验证过程,使新用户的逻辑,parse.com [英] The verification Procedure and making new users logic, parse.com

查看:223
本文介绍了验证过程,使新用户的逻辑,parse.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我停留在如何思考何时创建新的匿名用户。这是我的应用程序是如何设置现在。

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

我有三个ViewControllers。

I got three ViewControllers.

1) GetPhoneController ,2)的 VerificationController
,3)的ViewController

GetPhoneController:是,如果打开应用程序的用户没有用户存储的含义 [PFUser的currentUser]第一种观点; 等于为null,则此视图将被执行,否则的ViewController 将执行(支票在AppDelegate中完成)。该视图将刚刚得到的用户的电话号码在一个的UITextField并且被发送到下一个控制器

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::当这个观点被打开一个文本消息发送到一个验证code用户。我使用Twilio与解析。验证code被保存在用户对象的自定义字段用于匹配codeS供以后使​​用。(问题就在这里你也会知道为什么更高版本)。

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).

如果用户输入正确的验证code的检查完成后,如果用户没有做,然后我想匿名用户创建和移动到下一个控制器。为什么?因为如果在方案中被确认之前,他然后创建一个用户一个用户可能关闭下来的应用程序,然后用户被白白占用额外的空间中创建。

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.

所以,我的问题是我尝试保存验证code到用户,因为我要创建它验证之后不存在。

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?

感谢您!

推荐答案

如果您不想在解析来创建用户之前验证完成后,可以为您节省验证令牌 NSUserDefaults的

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

在VerificationController发送验证code中的方法...

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

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

接着,检查当用户输入code和水龙头按钮...

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.
  }
}

---新的信息编辑code一代发生服务器端---

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

如果你真的不希望创建一个用户,直到他们核实,code一代发生服务器端,你可以使用创建一个新的 VerificationToken 对象在解析。您可以通过生成用户设备标识符[NSUUID UUID] UUIDString] ,并存储在 NSUserDefaults的(这样,你不需要使用广告识别码,它在应用程序执行的持久)。在UUID与发送请求生成和发送code给用户,并将其保存在云code函数验证对象。

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.

VerificationController ,只发送了code。与您从 NSUserDefaults的中,搜索匹配,返回成功,并创建匿名用户的 VerificationToken 对象。

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.

最后,如果你担心有成千​​上万未完成 VerificationToken 的对象塞满了解析,只是告诉用户,他们只能持续24小时,并创建一个云计划code的工作去和删除都 VerificationToken 对象 createdAt 日期早于1天前,和安排为每天运行的任务。

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.

这篇关于验证过程,使新用户的逻辑,parse.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆