Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Commit

Permalink
Use recaptcha expired called
Browse files Browse the repository at this point in the history
Resolves #57 by using recaptcha's expired-callback instead of a hard-coded 2 min timeout
  • Loading branch information
TheSharpieOne committed Feb 6, 2016
1 parent 4e8d274 commit 43d40b3
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

scope.widgetId = null;

var sessionTimeout;
var removeCreationListener = scope.$watch('key', function (key) {
if (!key) {
return;
Expand All @@ -51,24 +50,15 @@
// Notify about the response availability
scope.onSuccess({response: gRecaptchaResponse, widgetId: scope.widgetId});
});

// captcha session lasts 2 mins after set.
sessionTimeout = $timeout(function (){
if(ctrl){
ctrl.$setValidity('recaptcha',false);
}
scope.response = "";
// Notify about the response availability
scope.onExpire({widgetId: scope.widgetId});
}, 2 * 60 * 1000);
};

vcRecaptcha.create(elm[0], key, callback, {

stoken: scope.stoken || attrs.stoken || null,
theme: scope.theme || attrs.theme || null,
tabindex: scope.tabindex || attrs.tabindex || null,
size: scope.size || attrs.size || null
size: scope.size || attrs.size || null,
'expired-callback': expired

}).then(function (widgetId) {
// The widget has been created
Expand All @@ -91,14 +81,19 @@
// reset the validity of the form if we were removed
ctrl.$setValidity('recaptcha', null);
}
if (sessionTimeout) {
// don't trigger the session timeout if we are no longer active
$timeout.cancel(sessionTimeout);
sessionTimeout = null;
}

cleanup();
}

function expired(){
if(ctrl){
ctrl.$setValidity('recaptcha',false);
}
scope.response = "";
// Notify about the response availability
scope.onExpire({widgetId: scope.widgetId});
}

function cleanup(){
// removes elements reCaptcha added.
angular.element($document[0].querySelectorAll('.pls-container')).parent().remove();
Expand Down

0 comments on commit 43d40b3

Please sign in to comment.