base-re-captcha-component.directive.d.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { AfterViewChecked, AfterViewInit, ElementRef, EventEmitter, Injector, NgZone, OnChanges, Renderer2, SimpleChanges } from "@angular/core";
  2. import { AbstractControl, ControlValueAccessor } from "@angular/forms";
  3. import { ReCaptchaType } from "../models/recaptcha-type.enum";
  4. import { ScriptService } from "../services/script.service";
  5. import * as i0 from "@angular/core";
  6. export declare abstract class BaseReCaptchaComponentDirective implements OnChanges, ControlValueAccessor, AfterViewInit, AfterViewChecked {
  7. protected renderer: Renderer2;
  8. protected zone: NgZone;
  9. protected injector: Injector;
  10. protected scriptService: ScriptService;
  11. /**
  12. * Prefix of the captcha element
  13. */
  14. protected readonly captchaElemPrefix = "ngx_captcha_id_";
  15. private setupCaptcha;
  16. /**
  17. * Google's site key.
  18. * You can find this under https://www.google.com/recaptcha
  19. */
  20. siteKey?: string;
  21. /**
  22. * Indicates if global domain 'recaptcha.net' should be used instead of default domain ('google.com')
  23. */
  24. useGlobalDomain: boolean;
  25. useEnterprise: boolean;
  26. /**
  27. * Type
  28. */
  29. type: "audio" | "image";
  30. /**
  31. * Language code. Auto-detects the user's language if unspecified.
  32. */
  33. hl?: string;
  34. /**
  35. * Tab index
  36. */
  37. tabIndex: number;
  38. /**
  39. * Called when captcha receives successful response.
  40. * Captcha response token is passed to event.
  41. */
  42. success: EventEmitter<string>;
  43. /**
  44. * Called when captcha is loaded. Event receives id of the captcha
  45. */
  46. load: EventEmitter<void>;
  47. /**
  48. * Called when captcha is reset.
  49. */
  50. reset: EventEmitter<void>;
  51. /**
  52. * Called when captcha is loaded & ready. I.e. when you need to execute captcha on component load.
  53. */
  54. ready: EventEmitter<void>;
  55. /**
  56. * Error callback
  57. */
  58. error: EventEmitter<void>;
  59. /**
  60. * Expired callback
  61. */
  62. expire: EventEmitter<void>;
  63. abstract captchaWrapperElem?: ElementRef;
  64. /**
  65. * Indicates if captcha should be set on load
  66. */
  67. private setupAfterLoad;
  68. /**
  69. * Captcha element
  70. */
  71. protected captchaElem?: HTMLElement;
  72. /**
  73. * Id of the captcha elem
  74. */
  75. protected captchaId?: number;
  76. /**
  77. * Holds last response value
  78. */
  79. protected currentResponse?: string;
  80. /**
  81. * If enabled, captcha will reset after receiving success response. This is useful
  82. * when invisible captcha need to be resolved multiple times on same page
  83. */
  84. protected resetCaptchaAfterSuccess: boolean;
  85. /**
  86. * Captcha type
  87. */
  88. protected abstract recaptchaType: ReCaptchaType;
  89. /**
  90. * Required by ControlValueAccessor
  91. */
  92. protected onChange: (value: string | undefined) => void;
  93. protected onTouched: (value: string | undefined) => void;
  94. /**
  95. * Indicates if captcha is loaded
  96. */
  97. isLoaded: boolean;
  98. /**
  99. * Reference to global reCaptcha API
  100. */
  101. reCaptchaApi?: any;
  102. /**
  103. * Id of the DOM element wrapping captcha
  104. */
  105. captchaElemId?: string;
  106. /**
  107. * Form Control to be enable usage in reactive forms
  108. */
  109. control?: AbstractControl | null;
  110. protected constructor(renderer: Renderer2, zone: NgZone, injector: Injector, scriptService: ScriptService);
  111. ngAfterViewInit(): void;
  112. ngAfterViewChecked(): void;
  113. /**
  114. * Gets reCaptcha properties
  115. */
  116. protected abstract getCaptchaProperties(): any;
  117. /**
  118. * Used for captcha specific setup
  119. */
  120. protected abstract captchaSpecificSetup(): void;
  121. ngOnChanges(changes: SimpleChanges): void;
  122. /**
  123. * Gets captcha response as per reCaptcha docs
  124. */
  125. getResponse(): string;
  126. /**
  127. * Gets Id of captcha widget
  128. */
  129. getCaptchaId(): number | undefined;
  130. /**
  131. * Resets captcha
  132. */
  133. resetCaptcha(): void;
  134. /**
  135. * Gets last submitted captcha response
  136. */
  137. getCurrentResponse(): string | undefined;
  138. /**
  139. * Reload captcha. Useful when properties (i.e. theme) changed and captcha need to reflect them
  140. */
  141. reloadCaptcha(): void;
  142. protected ensureCaptchaElem(captchaElemId: string): void;
  143. /**
  144. * Responsible for instantiating captcha element
  145. */
  146. protected renderReCaptcha(): void;
  147. /**
  148. * Called when captcha receives response
  149. * @param callback Callback
  150. */
  151. protected handleCallback(callback: any): void;
  152. private getPseudoUniqueNumber;
  153. private setupComponent;
  154. /**
  155. * Called when google's recaptcha script is ready
  156. */
  157. private onloadCallback;
  158. private generateNewElemId;
  159. private createAndSetCaptchaElem;
  160. /**
  161. * To be aligned with the ControlValueAccessor interface we need to implement this method
  162. * However as we don't want to update the recaptcha, this doesn't need to be implemented
  163. */
  164. writeValue(obj: any): void;
  165. /**
  166. * This method helps us tie together recaptcha and our formControl values
  167. */
  168. registerOnChange(fn: any): void;
  169. /**
  170. * At some point we might be interested whether the user has touched our component
  171. */
  172. registerOnTouched(fn: any): void;
  173. /**
  174. * Handles error callback
  175. */
  176. protected handleErrorCallback(): void;
  177. /**
  178. * Handles expired callback
  179. */
  180. protected handleExpireCallback(): void;
  181. static ɵfac: i0.ɵɵFactoryDeclaration<BaseReCaptchaComponentDirective, never>;
  182. static ɵdir: i0.ɵɵDirectiveDeclaration<BaseReCaptchaComponentDirective, never, never, { "siteKey": "siteKey"; "useGlobalDomain": "useGlobalDomain"; "useEnterprise": "useEnterprise"; "type": "type"; "hl": "hl"; "tabIndex": "tabIndex"; }, { "success": "success"; "load": "load"; "reset": "reset"; "ready": "ready"; "error": "error"; "expire": "expire"; }, never, never, false, never>;
  183. }
  184. //# sourceMappingURL=base-re-captcha-component.directive.d.ts.map