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

Commit

Permalink
Merge pull request #106 from TheSharpieOne/feature/iss-57
Browse files Browse the repository at this point in the history
Use recaptcha expired called
  • Loading branch information
iambrosi committed Feb 8, 2016
2 parents 45aabb3 + 43d40b3 commit 8f8dde7
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 @@ -32,7 +32,6 @@

scope.widgetId = null;

var sessionTimeout;
var removeCreationListener = scope.$watch('key', function (key) {
if (!key) {
return;
Expand All @@ -52,16 +51,6 @@
// 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, {
Expand All @@ -70,7 +59,8 @@
theme: scope.theme || attrs.theme || null,
type: scope.type || attrs.type || 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 @@ -93,14 +83,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 8f8dde7

Please sign in to comment.