2014-09-10 113 views
0
- (IBAction)forgotPassword:(id)sender { 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Direccion de Correo" message:@"Introduzca su correo electronico:" delegate:self cancelButtonTitle:@"Cancelar" otherButtonTitles:@"Aceptar", nil]; 
    alertView.alertViewStyle = UIAlertViewStylePlainTextInput; 
    [alertView show]; 


} 


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 

    if(buttonIndex ==1){ 
     NSLog(@"ok button clicked in forgot password alert view"); 
     NSString *email=[alertView textFieldAtIndex:0].text; 
     if ([email isEqualToString:@"email"]) { 
      UIAlertView *display; 
      display=[[UIAlertView alloc] initWithTitle:@"Email" message:@"Please enter password for resetting password" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil]; 
      [display show]; 

     }else{ 
      [PFUser requestPasswordResetForEmailInBackground:email block:^(BOOL succeeded, NSError *error) { 
       UIAlertView *display; 
       if(succeeded){ 
        display=[[UIAlertView alloc] initWithTitle:@"Correo electronico enviado" message:@"Por favor, revise su correo para resetear contraseña" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil]; 

       }else{ 
        display=[[UIAlertView alloc] initWithTitle:@"Correo fallido" message:@"el correo electronico no coincide con ninguno en la base de datos" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles: nil]; 
       } 
       [display show]; 
      }]; 
     } 
    } 
} 
+1

,问题是? – Olter 2014-09-10 10:15:40

+0

我想找到这个代码中的错误,不让我看到第二个AlertView。如果用户被发现与AlertView不一样 – 2014-09-10 10:17:33

+1

我会修复你的代码格式,但是你应该把这个解释添加到你的问题中。因为现在,真的很难理解,你在问什么。 – Olter 2014-09-10 10:20:21

回答

2

在你的下面的代码,

//Here you fire the query to check for email address in your parse backend 
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 

if (!error) { //If no error in your query then will enter below block 

//the objects is array of object it gets from your parse but in your case it return's zero which implies that there is no object with that email in your parse db. 

     if (objects.count ==0) { 

//As objects.count is zero that means no email exist so in that case you don't send email for password recovery and show a alert as below to user that email is invalid(meaning not exist) 

      UIAlertView *alertView =[[UIAlertView alloc]initWithTitle:@"Correo enviado" message:@"Por favor, revise su correo para resetear su contraseña" delegate:self cancelButtonTitle:@"Cancelar" otherButtonTitles:nil]; 
       [alertView show]; 

     } else { 
//In this, else case will enter when there is objects.count greater than zero which means that email exist on db. So, in that case you would request for password recovery as below. 

//Also could show a alert to let user know that request for password recovery was sent successfully. 

      [self sendEmail:emailTextField.text]; 

      //the query was successful, but found 0 results 
      //email does not exist in the database, dont send the email 
      //show your alert view here 
     } 

    } else { 
     NSLog(@"Error: %@ %@", error, [error userInfo]); 
    } 
}]; 

为什么再次检查条件(对象==无)为您的第一个条件(object.count == 0)做的事情。出于某种原因,两者都是相同的,所以没有任何意义。此外,我运行您的代码,我收到一个警报,输入一些文本,然后是标题为“Correo enviado”的警报。

如果我误解您的查询或其他任何内容,请让我知道。

+0

感谢您的反馈我真的appreaciate。是啊!你是对的。事实上,我只是在进行测试,最后是一场灾难。我知道。抱歉。所以;我想我需要删除第二,如果但我如何显示alertview时,电子邮件是不正确的?非常感谢。 – 2014-09-10 10:52:56

+0

对于电子邮件警报,当你没有从解析返回的对象时,那意味着没有用户使用这个电子邮件存在的解析端,所以只需显示警告消息“无效的电子邮件”和潜在的“请提供一个有效的电子邮件”,然后让用户可以看到您的alertView的父视图。 – nikhil84 2014-09-10 10:57:30

+0

你好Walle84。我再次写入代码,然后添加一些我想要的内容。我希望现在它更容易理解。首先,我想在查询成功的地方添加一行,但发现0个结果,然后数据库中不存在电子邮件,不发送电子邮件。提前致谢。 – 2014-09-10 20:43:41

2

为什么你要先查询多个查询才能找到用户详细信息(如果找到)发送ResetPasswordRequest,而不是使用重置请求的完成处理程序。

[PFUser requestPasswordResetForEmailInBackground:self.txtEmail.text block:^(BOOL succeeded,NSError *error) 
{ 

    if (!error) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:kAlertTitle message:[NSString stringWithFormat: @"Link to reset the password has been send to specified email"] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alert show]; 
     return; 

    } 
    else 
    { 
      NSString *errorString = [error userInfo][@"error"]; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:kAlertTitle message:[NSString stringWithFormat: @"Password reset failed: %@",errorString] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
     [alert show]; 
     return; 
    } 
}]; 

如果用户不存在解析会响应错误“错误:没有用户的电子邮件[email protected]发现”

问候,

阿米特

+0

对不起,阿米特,但它不起作用。我没有收到任何包含此代码的电子邮件。的确如此。 – 2014-09-10 20:08:13