From 85d28c13f9ce05057b69af3778f1ddb9bf79ed2a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 16 Mar 2018 16:11:18 +0100 Subject: [PATCH] MOBILE-2379 recaptcha: Reset recaptcha if error and fix iframe in iOS --- .../login/controllers/emailsignup.js | 6 ++++++ www/core/directives/iframe.js | 20 +++++++++++-------- www/core/directives/recaptcha.js | 12 +++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/www/core/components/login/controllers/emailsignup.js b/www/core/components/login/controllers/emailsignup.js index d0d219729e2..c6b5062324c 100644 --- a/www/core/components/login/controllers/emailsignup.js +++ b/www/core/components/login/controllers/emailsignup.js @@ -225,6 +225,9 @@ angular.module('mm.core.login') if (recaptchaV1Enabled) { // Error sending, request another capctha since the current one is probably invalid now. $scope.requestCaptchaV1(true); + } else { + // Reset captcha (if present). + $scope.$broadcast('mmCore:ResetRecaptchaV2'); } } }); @@ -234,6 +237,9 @@ angular.module('mm.core.login') if (recaptchaV1Enabled) { // Error sending, request another capctha since the current one is probably invalid now. $scope.requestCaptchaV1(true); + } else { + // Reset captcha V2 (if present). + $scope.$broadcast('mmCore:ResetRecaptchaV2'); } }).finally(function() { modal.dismiss(); diff --git a/www/core/directives/iframe.js b/www/core/directives/iframe.js index 6989dda34b8..52e444fd194 100644 --- a/www/core/directives/iframe.js +++ b/www/core/directives/iframe.js @@ -75,14 +75,18 @@ angular.module('mm.core') if (!contentWindow && el && el.getSVGDocument) { // It's probably an . Try to get the window. - var svgDoc = el.getSVGDocument(); - if (svgDoc && svgDoc.defaultView) { - contents = angular.element(svgdoc); - contentWindow = svgdoc.defaultView; - } else if (el.window) { - contentWindow = el.window; - } else if (el.getWindow) { - contentWindow = el.getWindow(); + try { + var svgDoc = el.getSVGDocument(); + if (svgDoc && svgDoc.defaultView) { + contents = angular.element(svgdoc); + contentWindow = svgdoc.defaultView; + } else if (el.window) { + contentWindow = el.window; + } else if (el.getWindow) { + contentWindow = el.getWindow(); + } + } catch (ex) { + // Error accessing document. } } diff --git a/www/core/directives/recaptcha.js b/www/core/directives/recaptcha.js index c1779acbee0..25bc0603b0a 100644 --- a/www/core/directives/recaptcha.js +++ b/www/core/directives/recaptcha.js @@ -132,6 +132,18 @@ angular.module('mm.core') scope.$watchGroup(['publickey', 'challengehash', 'challengeimage'], function() { setupCaptcha(scope); }); + + scope.$on('mmCore:ResetRecaptchaV2', function() { + // Reset the response. + scope.model.recaptcharesponse = ''; + + // Reload the iframe. + var currentSrc = scope.iframeSrc; + scope.iframeSrc = ''; + $timeout(function() { + scope.iframeSrc = currentSrc; + }); + }); } }; });