From c499493b4c56d3b01e67c5c6ca8720e7ddb00de5 Mon Sep 17 00:00:00 2001 From: Wojciech Taisner <wtaisner@man.poznan.pl> Date: Thu, 16 Sep 2021 10:00:58 +0200 Subject: [PATCH] NMAAS-1038 in case of captcha service errors send empty token --- src/app/shared/contact/contact.component.ts | 1 + src/app/welcome/passwordreset/password-reset.component.ts | 6 +++++- src/app/welcome/registration/registration.component.ts | 8 +++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app/shared/contact/contact.component.ts b/src/app/shared/contact/contact.component.ts index 58716ebe..2cbe500a 100644 --- a/src/app/shared/contact/contact.component.ts +++ b/src/app/shared/contact/contact.component.ts @@ -125,6 +125,7 @@ export class ContactComponent implements OnInit { private sendMail(data: any): Observable<void> { // submit captcha request return this.recaptchaV3Service.execute('contactForm').pipe( + catchError(_ => of('')), // in case of captcha error return empty token map((token) => { const result = {token, mail: new Mail()} // create mail object result.mail.otherAttributes = data; // set properties and mail attributes diff --git a/src/app/welcome/passwordreset/password-reset.component.ts b/src/app/welcome/passwordreset/password-reset.component.ts index 446faf46..3b65c5af 100644 --- a/src/app/welcome/passwordreset/password-reset.component.ts +++ b/src/app/welcome/passwordreset/password-reset.component.ts @@ -7,6 +7,8 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {PasswordValidator} from '../../shared'; import {PasswordStrengthMeterComponent} from 'angular-password-strength-meter'; import {ReCaptchaV3Service} from 'ng-recaptcha'; +import {catchError} from 'rxjs/operators'; +import {of} from 'rxjs'; @Component({ selector: 'app-passwordreset', @@ -53,7 +55,9 @@ export class PasswordResetComponent implements OnInit { public resetPassword() { if (this.form.valid) { - this.recaptchaV3Service.execute('password_reset').subscribe((captchaToken) => { + this.recaptchaV3Service.execute('password_reset').pipe( + catchError(_ => of('')), // in case of captcha error return empty token + ).subscribe((captchaToken) => { this.passwordReset.password = this.form.controls['newPassword'].value; this.passwordReset.token = this.token; this.userService.resetPassword(this.passwordReset, captchaToken).subscribe( diff --git a/src/app/welcome/registration/registration.component.ts b/src/app/welcome/registration/registration.component.ts index 18b8ce0a..a9ade492 100644 --- a/src/app/welcome/registration/registration.component.ts +++ b/src/app/welcome/registration/registration.component.ts @@ -5,14 +5,14 @@ import {AppConfigService} from '../../service/appconfig.service'; import {PasswordValidator} from '../../shared/common/password/password.component'; import {Component, OnInit, ViewChild} from '@angular/core'; import {FormGroup, FormBuilder, Validators} from '@angular/forms'; -import {Observable} from 'rxjs'; +import {Observable, of} from 'rxjs'; import {ModalInfoTermsComponent} from '../../shared/modal/modal-info-terms/modal-info-terms.component'; import {ModalInfoPolicyComponent} from '../../shared/modal/modal-info-policy/modal-info-policy.component'; import {ModalComponent} from '../../shared/modal'; import {PasswordStrengthMeterComponent} from 'angular-password-strength-meter'; import {TranslateService} from '@ngx-translate/core'; -import {map} from 'rxjs/operators'; +import {catchError, map} from 'rxjs/operators'; import {ReCaptchaV3Service} from 'ng-recaptcha'; @Component({ @@ -76,7 +76,9 @@ export class RegistrationComponent implements OnInit { } public onSubmit(): void { - this.recaptchaV3Service.execute('registration').subscribe((captchaToken) => { + this.recaptchaV3Service.execute('registration').pipe( + catchError(_ => of('')), // in case of captcha error return empty token + ).subscribe((captchaToken) => { if (!this.registrationForm.controls['termsOfUseAccepted'].value || !this.registrationForm.controls['privacyPolicyAccepted'].value) { this.sending = false; -- GitLab