Xcode忘了密码Parse

时间:2014-09-10 10:11:48

标签: ios objective-c xcode passwords reset

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

2 个答案:

答案 0 :(得分: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)中再次检查条件(objects == nil)。两者都是相同的,因此出于一个原因显示警报毫无意义。我还运行了你的代码,我收到了一个警报,输入了一些文字,然后是一个标题为#34; Correo enviado"的警报。

如果我误解了您的查询或其他任何内容,请告诉我。

答案 1 :(得分: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;
    }
}];

如果用户不在场,Parse将回复错误“错误:没有用户发现电子邮件xxxxxxxxx@xxx.com”

此致

阿米特

相关问题