3.0.0 • Published 11 months ago

ember-h-captcha v3.0.0

Weekly downloads
721
License
MIT
Repository
github
Last release
11 months ago

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.

3.0.0

11 months ago

2.5.2

1 year ago

2.5.1

2 years ago

2.5.0

2 years ago

2.4.0

2 years ago

2.3.0

2 years ago

2.2.4

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.1

2 years ago

2.2.0

3 years ago

2.1.7

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.47

3 years ago

2.0.46

3 years ago

2.0.44

3 years ago

2.0.45

3 years ago

2.0.42

3 years ago

2.0.43

3 years ago

2.0.40

3 years ago

2.0.41

3 years ago

2.0.37

3 years ago

2.0.38

3 years ago

2.0.35

3 years ago

2.0.36

3 years ago

2.0.33

3 years ago

2.0.34

3 years ago

2.0.39

3 years ago

2.0.31

3 years ago

2.0.32

3 years ago

2.0.30

3 years ago

2.0.29

3 years ago

2.0.28

3 years ago

2.0.27

3 years ago

2.0.26

3 years ago

2.0.24

3 years ago

2.0.25

3 years ago

2.0.22

3 years ago

2.0.23

3 years ago

2.0.21

3 years ago

2.0.20

3 years ago

2.0.19

3 years ago

2.0.18

3 years ago

2.0.17

3 years ago

2.0.16

3 years ago

2.0.15

3 years ago

2.0.13

3 years ago

2.0.14

3 years ago

2.0.11

3 years ago

2.0.12

3 years ago

2.0.10

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago