Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Parse.com&;小型企业应用程序:使用产品密钥的最佳实践_Ios_Objective C_Authentication_Parse Platform_Push Notification - Fatal编程技术网

Ios Parse.com&;小型企业应用程序:使用产品密钥的最佳实践

Ios Parse.com&;小型企业应用程序:使用产品密钥的最佳实践,ios,objective-c,authentication,parse-platform,push-notification,Ios,Objective C,Authentication,Parse Platform,Push Notification,我正在一个小企业的应用程序中使用Parse SDK,大约有3000名客户。我正在使用内置类PFUser在首次发布时注册所有用户,但我还需要: 限制应用程序的用户/客户端(总数) 授予业务人员权限,允许他们(从自己的设备)向所有商店客户端发送远程通知 为此,我考虑了这个过程: 我生成一个“用户密钥”列表。每个用户密钥是由15个字符组成的字符串,包括数字、小写和大写。我计划从一个(免费)网站生成这些密钥 我将这些用户密钥上传到Parse数据库中。每个userKey都将存储为userKey类的一个

我正在一个小企业的应用程序中使用Parse SDK,大约有3000名客户。我正在使用内置类PFUser在首次发布时注册所有用户,但我还需要:

  • 限制应用程序的用户/客户端(总数)
  • 授予业务人员权限,允许他们(从自己的设备)向所有商店客户端发送远程通知
为此,我考虑了这个过程:

  • 我生成一个“用户密钥”列表。每个用户密钥是由15个字符组成的字符串,包括数字、小写和大写。我计划从一个(免费)网站生成这些密钥
  • 我将这些用户密钥上传到Parse数据库中。每个userKey都将存储为userKey类的一个实例。我会手动将设置为TRUE的列/属性“isAdmin”(布尔值)添加到给定数量的用户键(比如8-10)。所有其他键都将这些属性设置为FALSE
  • 我将这组用户密钥交给业务所有者。然后,她拥有给定数量的“客户机”用户密钥,比如990,以及10个以上的“管理员”用户密钥
  • 无论用户是谁,当应用程序第一次在设备上启动时,都会提示她登录(事实上,我正在考虑检查[PFUser currentUser]是否已缓存在磁盘上?如果没有,则显示登录/登录页面。)
  • 这个新用户输入她的邮箱地址,作为她的用户名、密码和业务所有者提供给她的用户密钥
  • 如果邮件、密码和用户密钥输入格式正确(使用正则表达式检查),我将查询具有用户输入的相同ID的用户密钥(存储在Parse DB上)
  • 如果这个用户密钥甚至不存在,我会显示一个警报
  • 如果这个UserKey存在,我会查看它的“user”属性,即带有KVC符号的UserKey[@“user”]
  • 如果设置了此字段,则表示输入userKey已链接到PFUser(即,它已被提供给商店的客户端)。我显示和提醒
  • 如果未设置userKey[@“user”],则userKey为“free”。最后一步是要知道这个新用户是商店的工作人员还是客户
  • 我查看userKey[@“admin”],其中admin是手动输入的布尔值。如果userKey[@“admin”]=TRUE,那么我授权这个PFUser(现在缓存在磁盘上)发送远程通知 代码如下所示:

    - (void)signUpNewUser {
    
    NSString *userMail = self.mailTextField.text;
    NSString *userPassword = self.passwordTextField.text;
    NSString *userKeyInput = self.userKeyTextField.text;
    
    // == 1. Check Mail ==
    if (![self validateEmail:userMail]) {
        [self showAlertWithTitle:@"Mail invalide" subTitle:@"Entrez une adresse mail valide."];
        return;
    }
    // == 2. Check Password ==
    if ([self validatePassword:userPassword]) {
    
        // == 3. Check UserKey Input Format ==
        if ([self validateUserKeyFormat:userKeyInput]) {
    
            // == 4. Check if this UserKey exists ==
            PFQuery *userKeyQuery = [PFQuery queryWithClassName:@"UserKey"];
            [userKeyQuery whereKey:@"userKeyString" equalTo:userKeyInput];
    
            PFObject *fetchedUserKey = [userKeyQuery getFirstObject];
    
            // == 4.1. UserKey does not exist ==
            if (!fetchedUserKey) {
                [self showAlertWithTitle:@"Clé inconnue" subTitle:@"La clé saisie n'existe pas. Demandez au responsable du Club une clé personnelle différente."];
                return;
            }
    
            // == 4.2. UserKey exists, check if it is available ==
            if (fetchedUserKey) {
    
                // == 5.1. UserKey is already taken ==
                if (fetchedUserKey[@"user"] != nil) {
                    [self showAlertWithTitle:@"Clé déjà utilisée" subTitle:@"La clé saisie est déjà utilisée par un autre membre du Club. Demandez au responsable du Club une clé personnelle différente."];
                    return;
                }
    
                // == 5.2. UserKey is free. Create new PFUser, link with userKey & signUp ==
                if (fetchedUserKey[@"user"] == nil) {
    
                    PFUser *newUser = [PFUser user];
                    newUser.username = userMail;
                    newUser.password = userPassword;
                    newUser[@"isAdmin"] = fetchedUserKey[@"isAdmin"];
    
                    [newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    
                        if (error) {
                            NSLog(@"\n\n ** signUp ErrorDesc: %@\nError Code= %i",error.localizedDescription,error.code);
                        }
                        if (!error) {
                            NSLog(@"\n\n ** signUp SUCCESS!");
    
                            // I assume Parse will automatically create a One-to-One relationship between the UserKey and the PFUser. Am I right ?
                            fetchedUserKey[@"user"] = newUser;
                            [fetchedUserKey save];
    
                            newUser[@"userKey"] = fetchedUserKey;
                            [newUser save];
    
                            [self dismissViewControllerAnimated:YES completion:nil];
                        }
                    }];
                }
            }
        }
    }
    }
    
    我已经对代码进行了测试,它运行良好,可以处理各种情况(iPhone丢失、输入格式错误、用户密钥已被占用等)


    但由于这是我第一次在身份验证时限制用户访问,我想知道这种做法是否正确

    我投票结束这个问题,因为它似乎更适合我