diff --git a/Riot/ViewController/SettingsViewController.m b/Riot/ViewController/SettingsViewController.m index bc10ba763..1cbbd1723 100644 --- a/Riot/ViewController/SettingsViewController.m +++ b/Riot/ViewController/SettingsViewController.m @@ -2875,7 +2875,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); MXSession* session = [[AppDelegate theDelegate].mxSessions objectAtIndex:0]; MXK3PID *new3PID = [[MXK3PID alloc] initWithMedium:kMX3PIDMediumEmail andAddress:newEmailTextField.text]; - [new3PID requestValidationTokenWithMatrixRestClient:session.matrixRestClient nextLink:nil success:^{ + [new3PID requestValidationTokenWithMatrixRestClient:session.matrixRestClient isDuringRegistration:NO nextLink:nil success:^{ [self showValidationEmailDialogWithMessage:[NSBundle mxk_localizedStringForKey:@"account_email_validation_message"] for3PID:new3PID]; @@ -2947,7 +2947,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); MXK3PID *new3PID = [[MXK3PID alloc] initWithMedium:kMX3PIDMediumMSISDN andAddress:msisdn]; - [new3PID requestValidationTokenWithMatrixRestClient:session.matrixRestClient nextLink:nil success:^{ + [new3PID requestValidationTokenWithMatrixRestClient:session.matrixRestClient isDuringRegistration:NO nextLink:nil success:^{ [self showValidationMsisdnDialogWithMessage:[NSBundle mxk_localizedStringForKey:@"account_msisdn_validation_message"] for3PID:new3PID]; diff --git a/Riot/Views/Authentication/AuthInputsView.m b/Riot/Views/Authentication/AuthInputsView.m index c2dc767fe..b33b20cd8 100644 --- a/Riot/Views/Authentication/AuthInputsView.m +++ b/Riot/Views/Authentication/AuthInputsView.m @@ -291,7 +291,7 @@ return errorMsg; } -- (void)prepareParameters:(void (^)(NSDictionary *parameters))callback +- (void)prepareParameters:(void (^)(NSDictionary *parameters, NSError *error))callback { if (callback) { @@ -300,7 +300,7 @@ { // We trigger here a registration based on external inputs. All the required data are handled by the session id. NSLog(@"[AuthInputsView] prepareParameters: return external registration parameters"); - callback(externalRegistrationParameters); + callback(externalRegistrationParameters, nil); // CAUTION: Do not reset this dictionary here, it is used later to handle this registration until the end (see [updateAuthSessionWithCompletedStages:didUpdateParameters:]) @@ -438,24 +438,28 @@ submittedMSISDN = [[MXK3PID alloc] initWithMedium:kMX3PIDMediumMSISDN andAddress:msisdn]; [submittedMSISDN requestValidationTokenWithMatrixRestClient:restClient - nextLink:nil - success:^{ - - [self showValidationMSISDNDialogToPrepareParameters:callback]; - - } failure:^(NSError *error) { - - NSLog(@"[AuthInputsView] Failed to request msisdn token"); - - // Ignore connection cancellation error - if (([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled)) - { - return; - } - - callback(nil); - - }]; + isDuringRegistration:YES + nextLink:nil + success:^ + { + + [self showValidationMSISDNDialogToPrepareParameters:callback]; + + } + failure:^(NSError *error) + { + + NSLog(@"[AuthInputsView] Failed to request msisdn token"); + + // Ignore connection cancellation error + if (([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled)) + { + return; + } + + callback(nil, error); + + }]; // Async response return; @@ -492,39 +496,43 @@ [currentSession.session stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]]; [submittedEmail requestValidationTokenWithMatrixRestClient:restClient + isDuringRegistration:YES nextLink:nextLink - success:^{ - - NSURL *identServerURL = [NSURL URLWithString:restClient.identityServer]; - NSDictionary *parameters; - parameters = @{ - @"auth": @{@"session":currentSession.session, @"threepid_creds": @{@"client_secret": submittedEmail.clientSecret, @"id_server": identServerURL.host, @"sid": submittedEmail.sid}, @"type": kMXLoginFlowTypeEmailIdentity}, - @"username": self.userLoginTextField.text, - @"password": self.passWordTextField.text, - @"bind_msisdn": [NSNumber numberWithBool:self.isMSISDNFlowCompleted], - @"bind_email": @(YES) - }; - - [self hideInputsContainer]; - - self.messageLabel.text = NSLocalizedStringFromTable(@"auth_email_validation_message", @"Vector", nil); - self.messageLabel.hidden = NO; - - callback(parameters); - - } failure:^(NSError *error) { - - NSLog(@"[AuthInputsView] Failed to request email token"); - - // Ignore connection cancellation error - if (([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled)) - { - return; - } - - callback(nil); - - }]; + success:^ + { + + NSURL *identServerURL = [NSURL URLWithString:restClient.identityServer]; + NSDictionary *parameters; + parameters = @{ + @"auth": @{@"session":currentSession.session, @"threepid_creds": @{@"client_secret": submittedEmail.clientSecret, @"id_server": identServerURL.host, @"sid": submittedEmail.sid}, @"type": kMXLoginFlowTypeEmailIdentity}, + @"username": self.userLoginTextField.text, + @"password": self.passWordTextField.text, + @"bind_msisdn": [NSNumber numberWithBool:self.isMSISDNFlowCompleted], + @"bind_email": @(YES) + }; + + [self hideInputsContainer]; + + self.messageLabel.text = NSLocalizedStringFromTable(@"auth_email_validation_message", @"Vector", nil); + self.messageLabel.hidden = NO; + + callback(parameters, nil); + + } + failure:^(NSError *error) + { + + NSLog(@"[AuthInputsView] Failed to request email token"); + + // Ignore connection cancellation error + if (([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled)) + { + return; + } + + callback(nil, error); + + }]; // Async response return; @@ -547,12 +555,12 @@ @"bind_email": [NSNumber numberWithBool:self.isEmailIdentityFlowCompleted] }; - callback(parameters); + callback(parameters, nil); } else { NSLog(@"[AuthInputsView] reCaptcha stage failed"); - callback(nil); + callback(nil, [NSError errorWithDomain:MXKAuthErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:[NSBundle mxk_localizedStringForKey:@"not_supported_yet"]}]); } }]; @@ -580,11 +588,11 @@ } } - callback(parameters); + callback(parameters, nil); } } -- (void)updateAuthSessionWithCompletedStages:(NSArray *)completedStages didUpdateParameters:(void (^)(NSDictionary *parameters))callback +- (void)updateAuthSessionWithCompletedStages:(NSArray *)completedStages didUpdateParameters:(void (^)(NSDictionary *parameters, NSError *error))callback { if (callback) { @@ -635,12 +643,12 @@ } - callback (parameters); + callback (parameters, nil); } else { NSLog(@"[AuthInputsView] reCaptcha stage failed"); - callback (nil); + callback (nil, [NSError errorWithDomain:MXKAuthErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:[NSBundle mxk_localizedStringForKey:@"not_supported_yet"]}]); } }]; @@ -650,7 +658,7 @@ } NSLog(@"[AuthInputsView] updateAuthSessionWithCompletedStages failed"); - callback (nil); + callback (nil, [NSError errorWithDomain:MXKAuthErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:[NSBundle mxk_localizedStringForKey:@"not_supported_yet"]}]); } } @@ -1258,7 +1266,7 @@ return nil; } -- (void)showValidationMSISDNDialogToPrepareParameters:(void (^)(NSDictionary *parameters))callback +- (void)showValidationMSISDNDialogToPrepareParameters:(void (^)(NSDictionary *parameters, NSError *error))callback { __weak typeof(self) weakSelf = self; @@ -1332,7 +1340,7 @@ @"bind_email": [NSNumber numberWithBool:self.isEmailIdentityFlowCompleted] }; - callback(parameters); + callback(parameters, nil); } failure:^(NSError *error) { diff --git a/Riot/Views/Authentication/ForgotPasswordInputsView.m b/Riot/Views/Authentication/ForgotPasswordInputsView.m index 96e6486e1..ec5f50ea6 100644 --- a/Riot/Views/Authentication/ForgotPasswordInputsView.m +++ b/Riot/Views/Authentication/ForgotPasswordInputsView.m @@ -35,7 +35,7 @@ /** The block called when the parameters are ready and the user confirms he has checked his email. */ -@property (nonatomic, copy) void (^didPrepareParametersCallback)(NSDictionary *parameters); +@property (nonatomic, copy) void (^didPrepareParametersCallback)(NSDictionary *parameters, NSError *error); @end @@ -160,7 +160,7 @@ return errorMsg; } -- (void)prepareParameters:(void (^)(NSDictionary *parameters))callback +- (void)prepareParameters:(void (^)(NSDictionary *parameters, NSError *error))callback { if (callback) { @@ -208,81 +208,84 @@ [restClient forgetPasswordForEmail:self.emailTextField.text clientSecret:clientSecret sendAttempt:1 - success:^(NSString *sid) { - typeof(weakSelf) strongSelf = weakSelf; - if (strongSelf) { - strongSelf.didPrepareParametersCallback = callback; - - NSURL *identServerURL = [NSURL URLWithString:restClient.identityServer]; - strongSelf.parameters = @{ - @"auth": @{ - @"threepid_creds": @{ - @"client_secret": clientSecret, - @"id_server": identServerURL.host, - @"sid": sid - }, - @"type": kMXLoginFlowTypeEmailIdentity - }, - @"new_password": strongSelf.passWordTextField.text - }; - - [strongSelf hideInputsContainer]; - - strongSelf.messageLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"auth_reset_password_email_validation_message", @"Vector", nil), strongSelf.emailTextField.text]; - - strongSelf.messageLabel.hidden = NO; - - [strongSelf.nextStepButton addTarget:strongSelf - action:@selector(didCheckEmail:) - forControlEvents:UIControlEventTouchUpInside]; - - strongSelf.nextStepButton.hidden = NO; - } - } failure:^(NSError *error) { - NSLog(@"[ForgotPasswordInputsView] Failed to request email token"); - - // Ignore connection cancellation error - if (([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled)) - { - return; - } - - NSString *errorMessage; - if (error.userInfo[@"error"]) - errorMessage = error.userInfo[@"error"]; - else - errorMessage = error.localizedDescription; - - if (weakSelf) - { - typeof(self) self = weakSelf; - - if (self->inputsAlert) - { - [self->inputsAlert dismissViewControllerAnimated:NO completion:nil]; - } - - self->inputsAlert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"error"] message:errorMessage preferredStyle:UIAlertControllerStyleAlert]; - - [self->inputsAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { - - if (weakSelf) - { - typeof(self) self = weakSelf; - self->inputsAlert = nil; - if (self.delegate && [self.delegate respondsToSelector:@selector(authInputsViewDidCancelOperation:)]) - { - [self.delegate authInputsViewDidCancelOperation:self]; - } - } - - }]]; - - [self.delegate authInputsView:self presentAlertController:self->inputsAlert]; - } - }]; + success:^(NSString *sid) + { + typeof(weakSelf) strongSelf = weakSelf; + if (strongSelf) { + strongSelf.didPrepareParametersCallback = callback; + + NSURL *identServerURL = [NSURL URLWithString:restClient.identityServer]; + strongSelf.parameters = @{ + @"auth": @{ + @"threepid_creds": @{ + @"client_secret": clientSecret, + @"id_server": identServerURL.host, + @"sid": sid + }, + @"type": kMXLoginFlowTypeEmailIdentity + }, + @"new_password": strongSelf.passWordTextField.text + }; + + [strongSelf hideInputsContainer]; + + strongSelf.messageLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"auth_reset_password_email_validation_message", @"Vector", nil), strongSelf.emailTextField.text]; + + strongSelf.messageLabel.hidden = NO; + + [strongSelf.nextStepButton addTarget:strongSelf + action:@selector(didCheckEmail:) + forControlEvents:UIControlEventTouchUpInside]; + + strongSelf.nextStepButton.hidden = NO; + } + } + failure:^(NSError *error) + { + NSLog(@"[ForgotPasswordInputsView] Failed to request email token"); + + // Ignore connection cancellation error + if (([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled)) + { + return; + } + + NSString *errorMessage; + if (error.userInfo[@"error"]) + errorMessage = error.userInfo[@"error"]; + else + errorMessage = error.localizedDescription; + + if (weakSelf) + { + typeof(self) self = weakSelf; + + if (self->inputsAlert) + { + [self->inputsAlert dismissViewControllerAnimated:NO completion:nil]; + } + + self->inputsAlert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"error"] message:errorMessage preferredStyle:UIAlertControllerStyleAlert]; + + [self->inputsAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + self->inputsAlert = nil; + if (self.delegate && [self.delegate respondsToSelector:@selector(authInputsViewDidCancelOperation:)]) + { + [self.delegate authInputsViewDidCancelOperation:self]; + } + } + + }]]; + + [self.delegate authInputsView:self presentAlertController:self->inputsAlert]; + } + }]; // Async response return; @@ -293,7 +296,7 @@ } } - callback(self.parameters); + callback(nil, [NSError errorWithDomain:MXKAuthErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey:[NSBundle mxk_localizedStringForKey:@"not_supported_yet"]}]); } } @@ -362,7 +365,7 @@ { if (self.didPrepareParametersCallback) { - self.didPrepareParametersCallback(self.parameters); + self.didPrepareParametersCallback(self.parameters, nil); } } }