npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-h-captcha

v3.0.0

Published

Ember addon for hCaptcha.

Downloads

381

Readme

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.