ngx-recaptcha
Version:
Angular 2 component implementing Google's reCAPTCHA
74 lines (60 loc) • 2.21 kB
text/typescript
// Imports
import { Component, OnInit, Output, Input, EventEmitter, ViewChild } from '@angular/core';
import { RenderRecaptchaDirective } from '../render-recaptcha/render-recaptcha.directive';
//
// Main recpatcha component
//
export class CreateRecaptchaComponent implements OnInit {
// Properties passed through
onCaptchaComplete: EventEmitter<any> = new EventEmitter();
siteKey: string = null;
captchaStyle: any = null;
renderDelay: number = 500;
recaptchaId: string = 'grecaptcha';
public recaptchaInstance: RenderRecaptchaDirective;
//
// Called to initialise the object
//
ngOnInit() {
}
//
// Resets the current reCAPTCHA
//
resetRecaptcha() {
// Reset the instance if we have one
if (this.recaptchaInstance != null) {
this.recaptchaInstance.resetRecaptcha();
}
}
//
// Called when the Captcha has finished
//
/* tslint:disable:no-unused-variable */
public onCaptchaCompleted(data: string) {
/* tslint:enable:no-unused-variable */
// Pass through whether we succeeded or not
if (data != null) {
this.onCaptchaComplete.emit({
success: true,
token: data,
recaptcha: this,
});
} else {
this.onCaptchaComplete.emit({
success: false,
token: null,
recaptcha: this,
});
}
}
}