2015-02-05 265 views
0

我想知道是否有人能够提供Parse登录的代码示例,其中必须验证电子邮件地址,并且必须来自特定地址。我相信它是这样的; [查询whereKey:@“emailVerified”equalTo:[NSNumber numberWithBool:YES]]; 和 [查询whereKey:@“comment”containsString:@“@ gmail.com”]; 但我一直无法在我的项目中得到这个工作。 任何帮助或建议将是伟大的,但一段代码将是真棒解析PFLogin电子邮件验证

下面是我现有的代码,不会让一个未经验证的电子邮件用户登录,但现在我想添加的电子邮件处理

- (void)logInViewController:(PFLogInViewController *)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); 
} 

回答

0

您是否在允许用户登录之前执行此检查?如果是这样,可以轻松检查正在验证的电子邮件。

您可以创建一个辅助方法具有以下

- (void)methodname:(PFUser *)User { 

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

     if (![[user objectForKey:@"emailVerified"] boolValue]) { 
      // handle how you want to tell user they need to verify email address 
      [self redirectWithMessage:@"You must verify your email address"]; 
      return; 
     } 

} else if { 

      // check for specific address and handle if doesn't meet that requirement 

} else { 

    // The user verified and email is of correct address - send user to view 

} 

从手机的工作,请原谅它不是一个完整的代码块之中。

+0

这帮助,如果你看看我现在已经添加的代码你可以帮助更多一些。在此先感谢 – user3611162 2015-02-05 18:46:25

+0

您能否提供您的电子邮件要求的详细信息? – jimrice 2015-02-06 01:22:01

+0

我只想让一个电子邮件句柄能够登录到某个区域。它包含一些我不想与更多观众分享的信息。那么电子邮件已经被验证,所以你知道他们在那里工作。该电子邮件将是[email protected]。提前感谢您的任何建议 – user3611162 2015-02-06 01:51:26

0

感谢您的建议和意见。我设法解决这个问题,由于某种原因昨天无法解决。我相信答案是;

- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user { 

if (![[user objectForKey:@"emailVerified"] boolValue]){ 

    NSLog(@"User refresh"); 

    // make sure user did not recently verify email address 

    [user refresh]; 

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]; 
} 



    if (![[user objectForKey:@"email"] containsString:@"gmail.com"]) { 

     [[[UIAlertView alloc] initWithTitle:@"Error" message:@"You must have a validated gmail.com email to access this area." delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show]; 

     NSLog(@"Email not verified or not a gmail email"); 
} 
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]; 

}

0
if (user.objectForKey("emailVerified").boolValue == true){ 
        println("true") 
       } else { 
        println("false") 
       } 
+1

首先,这很快捷。其次,请在您的代码片段中添加一些解释形式。 – mmackh 2015-04-18 13:38:49