From ae7b380a7269e708e7e12b6a254221b3965487b7 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 4 Jun 2021 16:04:40 +0200 Subject: [PATCH] MOBILE-3320 signup: Expire recaptcha if error returned --- src/core/components/recaptcha/core-recaptcha.html | 2 +- src/core/components/recaptcha/recaptcha.ts | 11 +++++++++-- .../features/login/pages/email-signup/email-signup.ts | 11 ++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/components/recaptcha/core-recaptcha.html b/src/core/components/recaptcha/core-recaptcha.html index 9ce50edcf..d332e8958 100644 --- a/src/core/components/recaptcha/core-recaptcha.html +++ b/src/core/components/recaptcha/core-recaptcha.html @@ -7,7 +7,7 @@ {{ 'core.answered' | translate }} - + {{ 'core.login.recaptchaexpired' | translate }} diff --git a/src/core/components/recaptcha/recaptcha.ts b/src/core/components/recaptcha/recaptcha.ts index 987acf1b0..45e1c8934 100644 --- a/src/core/components/recaptcha/recaptcha.ts +++ b/src/core/components/recaptcha/recaptcha.ts @@ -87,8 +87,7 @@ export class CoreRecaptchaComponent implements OnInit { } if (event.data.action == 'expired') { - this.expired = true; - this.model![this.modelValueName] = ''; + this.expireRecaptchaAnswer(); } else if (event.data.action == 'callback') { this.expired = false; this.model![this.modelValueName] = event.data.value; @@ -101,4 +100,12 @@ export class CoreRecaptchaComponent implements OnInit { }); } + /** + * Expire the recaptcha answer. + */ + expireRecaptchaAnswer(): void { + this.expired = true; + this.model![this.modelValueName] = ''; + } + } diff --git a/src/core/features/login/pages/email-signup/email-signup.ts b/src/core/features/login/pages/email-signup/email-signup.ts index 0d6f53851..7e2462f6d 100644 --- a/src/core/features/login/pages/email-signup/email-signup.ts +++ b/src/core/features/login/pages/email-signup/email-signup.ts @@ -33,6 +33,7 @@ import { } from '@features/login/services/login-helper'; import { CoreNavigator } from '@services/navigator'; import { CoreForms } from '@singletons/form'; +import { CoreRecaptchaComponent } from '@components/recaptcha/recaptcha'; /** * Page to signup using email. @@ -45,6 +46,7 @@ import { CoreForms } from '@singletons/form'; export class CoreLoginEmailSignupPage implements OnInit { @ViewChild(IonContent) content?: IonContent; + @ViewChild(CoreRecaptchaComponent) recaptchaComponent?: CoreRecaptchaComponent; @ViewChild('ageForm') ageFormElement?: ElementRef; @ViewChild('signupFormEl') signupFormElement?: ElementRef; @@ -341,9 +343,12 @@ export class CoreLoginEmailSignupPage implements OnInit { CoreDomUtils.showAlert(Translate.instant('core.success'), message); CoreNavigator.back(); } else { - if (result.warnings && result.warnings.length) { - let error = result.warnings[0].message; - if (error == 'incorrect-captcha-sol') { + this.recaptchaComponent?.expireRecaptchaAnswer(); + + const warning = result.warnings?.[0]; + if (warning) { + let error = warning.message; + if (error == 'incorrect-captcha-sol' || (!error && warning.item == 'recaptcharesponse')) { error = Translate.instant('core.login.recaptchaincorrect'); }