hCaptcha addon for Emberjs.
- Ember.js v3.28 or above
- Embroider or ember-auto-import v2
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
};
Add the component to your template like this:
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
// ...
}
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:
then in your component or controller 's actions:
@action
onCaptchaExpired() {
// your custom logic here
}
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:
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();
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:
then in your component or controller 's actions:
@action
onCaptchaResolved() {
// ...
}
@action
onCaptchaRendered(instance) {
// your custom onRender logic
}
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:
then in your component or controller 's actions:
@action
onCaptchaResolved() {
// ...
}
@action
onCaptchaError(error) {
// Warn user
}
You can pass hCaptcha
the following properties:
sitekey
theme
size
tabIndex
Their meaning is described on this official doc.
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
};
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.