VividCortex / angular-recaptcha

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

Use expired-callback to expire captcha #57

Closed TheSharpieOne closed 8 years ago

TheSharpieOne commented 9 years ago

I just looked at the API docs for recaptcha, it looks like they added an expired-callback attribute which expires and the user needs to solve a new CAPTCHA. Currently, because this API attribute wasn't there previously, the solution depends on a timeout. It should be changed to use this new API method.

sparkyfen commented 9 years ago

:+1:

thatcatcancode commented 9 years ago

+1

jcsena commented 9 years ago

+1

KalinKanev commented 9 years ago

+1

jpmckearin commented 9 years ago

This is implemented but not yet documented. Looking here, there is a onExpire attribute on the directive. I'll submit a PR with the documentation change.

TheSharpieOne commented 9 years ago

@jpmckearin Yes, there is an implementation, I originally did it (sorry for not documenting it). The problem is, when I did it, reCaptcha did not have the expired-callback attribute they have now. Thus the current implementation uses a timeout which is hard-coded to 2 mins (as at the time 2 mins was (and currently is) how long it takes for the session to expire). But this may change and this directive should not rely on the hard-coded value. Instead, it should use the new expired-callback that reCaptcha provides to trigger the validity and end-user callback.

tl;dr This ticket it to change from the timeout to the reCaptcha callback.

jcsena commented 9 years ago

The solutions is send function is using expired-callback(google) service.js

//service.js
create: function (elm, key, fn, expired, conf) {
                conf.callback = fn;
                conf.sitekey = key;
                conf['expired-callback'] = expired;
                return getRecaptcha().then(function (recaptcha) {
                    return recaptcha.render(elm, conf);
                });
            },

directive.js

//directive.js
function expired(){
if(angular.isDefined(attrs.onExpire)){
  scope.onExpire();
}
}

 vcRecaptcha.create(elm[0], key, callback, expired {
                        theme: scope.theme || attrs.theme || null,
                        tabindex: scope.tabindex || attrs.tabindex || null
                    })
TheSharpieOne commented 9 years ago

@jcsena that wouldn't work as well as you would expect. When reCaptcha calls the expire callback it would be outside of angular's knowledge and would require an additional digest to register the changes made in the callback. It would also break backwards compatibility as the current expire callback passes the local variable of the widget id.

tl;dr That is not the angular way to do that.

jcsena commented 9 years ago

Mmm it is posible but, i implement this code with some modifications and this callback i can made the expire event and no problem

TheSharpieOne commented 9 years ago

This is not resolved, the PR that closed this only documented the existing feature. This ticket is to update the existing feature to use the method that is now provided by recaptcha.