Socket
Socket
Sign inDemoInstall

ember-h-captcha

Package Overview
Dependencies
539
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ember-h-captcha

Ember addon for hCaptcha.


Version published
Weekly downloads
82
decreased by-20.39%
Maintainers
1
Install size
31.9 MB
Created
Weekly downloads
 

Readme

Source

ember-h-captcha

hCaptcha addon for Emberjs.

Install

Compatibility

  • Ember.js v3.28 or above
  • Embroider or ember-auto-import v2

Configure

You need to generate a valid Site Key / Secret Key pair on hCaptcha site. Then, you need to set your Site Key in the ENV var on your config/environment.js file, like this:

var ENV = {
  // ...
};

ENV['ember-h-captcha'] = {
  jsUrl: 'https://hcaptcha.com/1/api.js', // default
  sitekey: 'your-site-key',
  hl: 'tr', // Ex: Turkish
};

Basic Usage

Add the component to your template like this:

<HCaptcha @onSuccess={{fn this.onCaptchaResolved}} />

then in your component or controller 's actions:

@action
onCaptchaResolved(response) {
  this.model.set('response', response);
  // You should then save your model and the server would validate response
  // ...
}

Advanced Usage

Handling Expiration

You know, after some time the hCaptcha response expires; hCaptcha 's default behavior is to invoke the reset method. But, if you want to perform custom behavior instead (e.g. transitioning to another route) you can pass your custom action via the onExpired property, like this:

<HCaptcha
  @onSuccess={{fn this.onCaptchaResolved}}
  @onExpired={{fn this.onCaptchaExpired}}
/>

then in your component or controller 's actions:

@action
onCaptchaExpired() {
  // your custom logic here
}

Triggering Reset

You might want to arbitrarily trigger hCaptcha reset. For example, if your form submission fails for errors on other fields, you might want to force user to solve a new hCaptcha challenge. To do that, first you'll need to grab a reference to hCaptcha component in your template, like this:

<HCaptcha
  @onSuccess={{fn this.onCaptchaResolved}}
  @onRender={{fn (mut this.hCaptcha)}}
/>

then you'll be able to invoke reset() method on hCaptcha property anywhere in your component or controller 's code, like this:

this.hCaptcha.reset();

onRender Callback

You might want to pass a callback function that will be called after the hCaptcha renders on the page. onRender callback also returns component instance. This is great for things like loading spinners. To do so, you can do something like this:

<HCaptcha
  @onSuccess={{fn this.onCaptchaResolved}}
  @onRender={{fn this.onCaptchaRendered}}
/>

then in your component or controller 's actions:

@action
onCaptchaResolved() {
  // ...
}

@action
onCaptchaRendered(instance) {
  // your custom onRender logic
}

onError Callback

You might want to pass a callback function that will be called after the error occured. To do so, you can do something like this:

<HCaptcha
  @onSuccess={{fn this.onCaptchaResolved}}
  @onError={{fn this.onCaptchaError}}
/>

then in your component or controller 's actions:

@action
onCaptchaResolved() {
  // ...
}

@action
onCaptchaError(error) {
  // Warn user
}

Customization

You can pass hCaptcha the following properties:

  • sitekey
  • theme
  • size
  • tabIndex

Their meaning is described on this official doc.

Configuring source JavaScript URL

var ENV = {
  // ...
};

ENV['ember-h-captcha'] = {
  jsUrl: 'https://hcaptcha.com/1/api.js', // default
  sitekey: 'your-site-key',
  hl: 'tr', // Locale Code - Ex: tr: Turkish
};

License

Most of the README file taken from the ember-g-recaptcha. hCaptcha mostly compatible with Google reCaptcha.

ember-hCaptcha is released under the MIT License.

Keywords

FAQs

Last updated on 23 Apr 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc