captcha-com / angular-captcha

BotDetect CAPTCHA: Angular Captcha Module (TypeScript: Angular 2/4/5/6/7/8+).
https://captcha.com/angular-captcha.html
16 stars 9 forks source link

Feature Request: Need ability to configure captchaEndpoint at runtime. #4

Closed harora-ot closed 5 years ago

harora-ot commented 5 years ago

The current way of initializing the module requires the config to be specified while loading the module. We have a requirement where the endpoint is not known until needed. But there is no way to re-configure the config, as the component fires the request from onInit() itself.

botdetect-support commented 5 years ago

This is supported in the Angular Captcha Module since v3.6.0. After you import Angular Captcha Module in your app.module.ts:

// import the Angular Captcha Module 
import { BotDetectCaptchaModule } from 'angular-captcha'; 

@NgModule({
  imports: [
    ...
    BotDetectCaptchaModule
  ],
  ...
})

set the captchaEndpoint in your component:

import { CaptchaComponent } from 'angular-captcha'; 

export class YourFormWithCaptchaComponent {

  ngOnInit(): void {
    this.captchaComponent.captchaEndpoint = 
      // if you have asp.net on backend
      'https://your-app-backend-hostname.your-domain.com/simple-captcha-endpoint.ashx';

      // if you have java on backend
      // 'https://your-app-backend-hostname.your-domain.com/simple-captcha-endpoint';

      // if you have php on backend
      //'https://your-app-backend-hostname.your-domain.com/botdetect-captcha-lib/simple-botdetect.php';
  }

Run the following command to get the latest version:

npm i angular-captcha@latest

Thanks for reporting the issue! If you have any further questions, please feel free to contact us at: https://captcha.com/contact.html