【问题标题】:how to check if PFUser has verified it's email - Xcode Parse如何检查 PFUser 是否已验证其电子邮件 - Xcode Parse
【发布时间】:2014-10-16 15:12:22
【问题描述】:

我正在尝试检查当前用户之前是否验证过它的电子邮件 他们进行下一步。我在做什么错请帮助谢谢。在后台保存的电话号码有效。当我调用“SavePhoneInBackground”时,应用程序崩溃

(SVProgressHUd 是活动指标)

-(void) SavePhoneInBackground  {

    PFUser *user = [PFUser currentUser];
    user[@"phone"] = _phone_register.text;

    [user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

        if (!error) {
            NSLog(@"PhoneUpdatingSucces!");
            _phone_register.text = nil;
            [self checkUserEmailVerify];

        }else {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops!" message:@"Something went wrong! Try again." delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
            [alert show];
            [SVProgressHUD dismiss];
            NSLog(@"There was an error in the registration!");
        }
    }];
}


-(void) checkUserEmailVerify {

    PFUser *user = [PFUser currentUser];

    if (![[user objectForKey:@"emailVerified"] boolValue]) {
        // Refresh to make sure the user did not recently verify
        [user refresh];

        if (![[user objectForKey:@"emailVerified"] boolValue]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops!" message:@"You need to verify your emailadress!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
            return;
            [SVProgressHUD dismiss];
        }
    }
    // This is a triumph.
    [SVProgressHUD dismiss];
    [self performSegueWithIdentifier:@"login2" sender:self];

}

【问题讨论】:

    标签: xcode email parsing verify pfuser


    【解决方案1】:
    func giveCaketoUser(user: PFUser) {
                    if (user.objectForKey("emailVerified").boolValue == true){
                        println("true")
                    } else {
                        println("flase")
                    }
                }
    

    【讨论】:

    • 当代码不言自明时,我认为不需要任何额外的信息细节。 :\
    • ^没错,就像 :D Talk 很便宜。给我看代码 - Linus Torvalds。
    【解决方案2】:

    这是我在最近的一个项目中使用的东西:

    - (BOOL)validateEmail:(NSString *)emailStr {
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:emailStr];
    }
    

    您可以使用正则表达式的其他操作。当我使用这种方法时,我遇到的问题是项目将继续注册用户,同时仍然显示我的自定义警报和 NSLog 错误,但这可能是我的失败而不是方法。

    希望这会给您带来正确的方向!

    【讨论】:

      【解决方案3】:

      这就是我在我的应用程序中的做法,它只会让经过验证的电子邮件用户访问。您需要根据需要对其稍作修改。

      - (void)logInViewController:(MyLogInViewController *)logInController didLogInUser:(PFUser *)user {
      
      if (![[user objectForKey:@"emailVerified"] boolValue]){
          NSLog(@"User not validated email");
          [[[UIAlertView alloc] initWithTitle:@"Access restricted" message:@"To access this area please validate your email address" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
      }
      else if ([[user objectForKey:@"emailVerified"] boolValue]){
          NSLog(@"Email validated");
          [self dismissViewControllerAnimated:YES completion:NULL];
          [[[UIAlertView alloc] initWithTitle:@"Welcome back" message:(@"%@", user.username) delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
      }
      
      // [self dismissViewControllerAnimated:YES completion:NULL];
      
      NSLog(@"Login sucessfull and username is %@",user.username);
      

      }

      如果您还没有解决,希望这对您有所帮助!

      【讨论】:

      • 这篇文章与我现在遇到的一个问题有关。在我的情况下,我无法使用 [PFUser currentUser] (即使使用 allKeys)获得 emailVerified 字段,尽管它存在于服务器端。一些测试(连接到另一个服务器应用程序)似乎表明客户端正在工作,但我不知道我可能在服务器上错过了什么。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      • 2020-11-13
      • 2021-10-10
      • 2012-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多