VividCortex / angular-recaptcha

AngularJS directive to add a reCaptcha widget to your form
http://vividcortex.github.io/angular-recaptcha/
MIT License
496 stars 258 forks source link

Document how to use invisible reCAPTCHA #205

Open odedniv opened 7 years ago

odedniv commented 7 years ago

Apart from adding invisible to the possible values of the size option, there is no real explanation on how to use this directive with invisible reCAPTCHA.

I've been using size="invisible" with ng-model, but it doesn't set the model's value. I see a badge on the bottom right of my screen.

Your project is very much appreciated!

notflorian commented 7 years ago

Hi,

I need to submit a form with <form action="/signupValidation" method="GET">, without using ng-submit="submit().

It works well with the checkbox recaptcha, but don't works with size="invisible".

Can you please improve the documentation of the invisble reCAPTCHA? Is it possible to use it without ng-submit="submit() and $scope.submit = function(event) { vcRecaptchaService.execute(); }; ?

DimitarNestorov commented 7 years ago

@thewarpaint I see that you've added those lines in README.

Can you tell us what we're missing? Or give us a simple working example?

thewarpaint commented 7 years ago

@dimitarnestorov I'll try to set up a basic JSFiddle using the invisible option.

mattW711 commented 7 years ago

I am trying to implement the invisible recaptcha as well. I have an invisible recaptcha key, and it is successfully verifying the response on the server side, but is always poping up an image selection test before sumbitting the form, so not invisible?

Otherwise is there a way to only require checkbox and not open the image selection everytime?

RaghuMurugesan commented 6 years ago

Question: How to use .then method for vcRecaptchaService.execute()?

Is there anything like vcRecaptchaService.execute().then(ret => { //do something here }) ?

RaghuMurugesan commented 6 years ago

Question: How to use .then method for vcRecaptchaService.execute()?

Is there anything like vcRecaptchaService.execute().then(ret => { //do something here }) ?

TheSharpieOne commented 6 years ago

Google's recaptcha execute does not return anything, then this library cannot return anything. When the execute is done, the callback will be called. The callback sets the value on the model AND triggers the user provided callback with the value and the widgetId.

A change could be made so that the vcRecaptchaService's create wraps the callback so that it knows when the callback is triggered and then can return a promise which gets resolved when that callback wrapper is called.

josduj commented 6 years ago

This is how I've done it...

In controller

this.onSubmit = () => {
    vcRecaptchaService.execute(this.widgetId)
}

this.onSuccess = token => {
    submitAndValidateOnBackend({
        // form data
        token: token,
    }).then(res => {
        console.log('success!')
    }).catch(err => {
        console.log('error')
        vcRecaptchaService.reload(this.widgetId)
    })
}

In template

<form ng-submit="$ctrl.onSubmit()">

    ...

    <div vc-recaptcha
         size="invisible"
         on-create="$ctrl.widgetId = widgetId"
         on-success="$ctrl.onSuccess(response)">
    </div>

    <button type="submit">Submit</button>
</form>
sejas commented 6 years ago

You just need to call to grecaptcha.execute() Maybe with a little timeout:

   $timeout(function () {
        grecaptcha.execute()
     }, 1000)

You don't need to add a form tag in the html, just the vc-recaptcha:

      <div vc-recaptcha
           key="ctrl.key"
           size="invisible"
           on-create="ctrl.widgetId = widgetId"
           on-success="ctrl.onSuccess(response)">
      </div>

I will add this code to the README.md to show the example ;)