/** * Recaptcha Component Implementation */ import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core'; import { ReCaptchaComponent } from 'angular2-recaptcha'; import { RecaptchaResponse } from '../../models/recaptcha/recaptchaResponse'; @Component({ selector: 'core-captcha-element', templateUrl: './captcha.component.html', }) export class CaptchaComponent implements OnChanges { @ViewChild(ReCaptchaComponent) captcha: ReCaptchaComponent; @Input() siteKey: string; @Input() size: string; @Input() isResetCaptcha: boolean; @Output() captchaResponseEmitter = new EventEmitter(); @Output() captchaExpiredEmitter = new EventEmitter(); public recaptchaResponse: RecaptchaResponse = { isExpired: false, response: '', }; public ngOnChanges(): void { if (this.isResetCaptcha) { this.captcha.reset(); } } /** * @description: callback from the reCaptcha component * @param response: the response string from reCaptcha */ public handleCorrectCaptcha(response: string): void { this.recaptchaResponse.response = response; this.captchaResponseEmitter.emit(this.recaptchaResponse); } /** * @description: expired callback from the reCaptcha component */ public captchaExpired(): void { this.recaptchaResponse.isExpired = true; this.captchaExpiredEmitter.emit(this.recaptchaResponse); } }