简体   繁体   English

解析:无需注册即可创建/保存新用户

[英]Parse: Create/Save New User without signUp

It seems Parse does not let me create new users, unless the sign up block is called. 似乎Parse不允许我创建新用户,除非调用了注册块。

It also seems that Parse doesn't let you edit username/password unless that user is currentUser logged in. 似乎该Parse不允许您编辑用户名/密码,除非该用户是currentUser登录。

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]

PS Here's the elevator pitch. PS这是电梯的音调。 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. 他们注册时,我登录了先前创建的用户(正在检查电话),然后他们在收件箱中看到我的“聊天室”。

Okay, here's the steps I had to take. 好的,这是我必须采取的步骤。

On the Signin End 在登录端

  1. Enable enableAutomaticUser for anonymous user. 为匿名用户启用enableAutomaticUser

  2. PFQuery for user registering to make sure his account doesn't exist based on his phoneNumber PFQuery用户注册,以确保他的帐户不存在基于他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 . 如果PFQuery有一个对象,请保存该PFUser ,然后在文本消息验证为true使用他的凭证登录。

On Signup End 在注册结束时

  1. For each phoneNumber , make sure a user doesn't already exist. 对于每个phoneNumber ,请确保没有用户。 If it does, forget that phoneNumber , add the PFuser 如果是这样,请忘记该phoneNumber ,添加PFuser

  2. Enumerate each phoneNumber for Register using the REST API 枚举每个电话phoneNumber以使用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 { } }]; } 

You could look at using enableAutomaticUser . 您可以看看使用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. 您可以设置用户的电子邮件和密码,然后保存。

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. 似乎有点破烂,但对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在parse.com中注册新用户? - Is it possible to signup new user in parse.com? Parse.com:在新用户注册后向管理员发送电子邮件 - Parse.com: Sending email to admin after new user signup 没有注册的iOS用户注册/身份验证(使用Parse / Swift) - iOS user registration/authentication without signup (using Parse / Swift) iOS-Swift:解析注册-即使文本验证阻止了新用户的保存, - iOS - Swift: Parse signup - new user is saved even though text validation should prevent it 快速创建一个新的分析对象,而无需数据 - Create a new parse object without data in swift 使用Parse作为后端在Xcode 6中使用Swift创建注册 - Create signup with Swift in Xcode 6 using Parse as backend Swift:更新解析用户(PFUser)并在新注册后将图像保存到其中 - Swift: Update Parse User (PFUser) and save image to it after new registration 表达式类型不明确,在实现解析注册时没有更多上下文错误 - Type of expression is ambiguous without more context error on implementing parse signup 使用Parse在用户注册时添加个人资料图片-iOS - Adding profile picture at user signup using Parse - iOS 在当前线程(signUp :)上执行Parse.com用户注册并检索NSError - perform Parse.com user signup on the current thread (signUp:) and retrieving the NSError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM