Ios Parse.com&;小型企业应用程序:使用产品密钥的最佳实践
我正在一个小企业的应用程序中使用Parse SDK,大约有3000名客户。我正在使用内置类PFUser在首次发布时注册所有用户,但我还需要: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类的一个
- 限制应用程序的用户/客户端(总数)
- 授予业务人员权限,允许他们(从自己的设备)向所有商店客户端发送远程通知
- (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丢失、输入格式错误、用户密钥已被占用等)
但由于这是我第一次在身份验证时限制用户访问,我想知道这种做法是否正确 我投票结束这个问题,因为它似乎更适合我