简体   繁体   English

如何保存未使用Parse登录的用户?

[英]How to save user that is not logged in with Parse?

I am working on an app that requires being able to search for partners to play with. 我正在开发一个需要能够搜索合作伙伴的应用程序。 Obviously, saving for the user is not an issue, but I'm not sure what would be the best way to modify the data for the other user. 显然,为用户保存不是问题,但是我不确定为其他用户修改数据的最佳方法是什么。 Perhaps sending a message to the other user which automatically gets read upon login and adds the relation status? 也许向其他用户发送一条消息,该消息在登录时自动被读取并添加了关系状态?

Here's what I have - it finds a random player from all the players also searching for a game and adds them to the "partners" relation. 这就是我所拥有的-它从所有也在搜索游戏的玩家中找到一个随机玩家,并将其添加到“合作伙伴”关系中。 Now how would I have this happen for the other user as well?: 现在,其他用户也将如何处理呢?:

- (IBAction)searchForPlayer:(id)sender {


     [self.currentUser setObject:@0 forKey:@"searching"];

    PFQuery *findPotential = [PFQuery queryWithClassName:@"_User"];
    [findPotential whereKey:@"searching" equalTo:@1];
    [findPotential findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

        int partnerNum = arc4random_uniform(objects.count);
        PFUser *newPartner = [objects objectAtIndex:partnerNum];

        if(error){
            NSLog(@"Error!");
        }

        else {

            if (objects.count == 0|| [newPartner.objectId isEqualToString:self.currentUser.objectId]) {
                NSLog(@"None found");
                [self.currentUser setObject:@1 forKey:@"searching"];
            }

            else {

                PFRelation *partners = [self.currentUser relationForKey:@"partners"];
                [partners addObject:newPartner];
                NSLog(@"Partner is: %@", newPartner.username);
                [self.currentUser setObject:@0 forKey:@"searching"];
            }
        }
    }];

[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if(error){
        NSLog(@"Error!");
    }
  }];
}

You don't ever want to do something like this client-side. 您永远都不想做这样的客户端。 For security purposes, a User can't alter another user. 为了安全起见,一个用户不能更改另一个用户。 Use Cloud Code. 使用云代码。 Call a function, and in that function verify you really want to do this, and then use the Master Key to query for and alter other objects. 调用一个函数,并在该函数中验证您确实要执行此操作,然后使用主键查询和更改其他对象。

You can mostly just convert your Objective-C query/example to JavaScript, put it inside a Cloud Function that accepts a few parameters, and put this at the top: 您基本上可以将Objective-C查询/示例转换为JavaScript,将其放在接受一些参数的Cloud Function中,然后将其放在顶部:

Parse.Cloud.useMasterKey();

Or, you can provide the master key individually to specific methods, such as: 或者,您可以分别为特定方法提供主密钥,例如:

object.save(null, { useMasterKey: true }).then(function(object) { ...

Read up on the Cloud Code docs here: https://parse.com/docs/cloud_code_guide 在此处阅读Cloud Code文档: https//parse.com/docs/cloud_code_guide

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM