Yeah, checking captcha timeout is probably better like that.

This commit is contained in:
Nicolas Stepien 2012-01-23 20:52:00 +01:00
parent e357fec7f5
commit 60a62232ad
2 changed files with 16 additions and 26 deletions

View File

@ -1442,22 +1442,19 @@
return window.location = 'javascript:(function(){Recaptcha.focus_response_field=function(){}})()'; return window.location = 'javascript:(function(){Recaptcha.focus_response_field=function(){}})()';
}, },
save: function() { save: function() {
var captchas, length, now, response; var captcha, captchas, response;
if (!(response = this.input.value)) return; if (!(response = this.input.value)) return;
captchas = $.get('captchas', []); captchas = $.get('captchas', []);
now = Date.now(); while ((captcha = captchas[0]) && captcha.time < Date.now()) {
if (captchas.length) { captchas.shift();
while (captchas[0].time < now) {
captchas.shift();
}
} }
length = captchas.push({ captchas.push({
challenge: this.challenge.firstChild.value, challenge: this.challenge.firstChild.value,
response: response, response: response,
time: this.timeout time: this.timeout
}); });
$.set('captchas', captchas); $.set('captchas', captchas);
this.count(length); this.count(captchas.length);
return this.reload(); return this.reload();
}, },
load: function() { load: function() {
@ -1545,7 +1542,7 @@
return $.add(d.body, qr.el); return $.add(d.body, qr.el);
}, },
submit: function(e) { submit: function(e) {
var captcha, captchas, challenge, err, file, m, now, post, reader, reply, response, threadID, time; var captcha, captchas, challenge, err, file, m, post, reader, reply, response, threadID;
if (e != null) e.preventDefault(); if (e != null) e.preventDefault();
qr.message.send({ qr.message.send({
abort: true abort: true
@ -1555,11 +1552,8 @@
err = 'Error: No file selected.'; err = 'Error: No file selected.';
} else { } else {
captchas = $.get('captchas', []); captchas = $.get('captchas', []);
if (captchas.length) { while ((captcha = captchas[0]) && captcha.time < Date.now()) {
now = Date.now(); captchas.shift();
while ((time = captchas[0].time) && time < now) {
captchas.shift();
}
} }
if (captcha = captchas.shift()) { if (captcha = captchas.shift()) {
challenge = captcha.challenge; challenge = captcha.challenge;

View File

@ -1071,16 +1071,14 @@ qr =
return unless response = @input.value return unless response = @input.value
captchas = $.get 'captchas', [] captchas = $.get 'captchas', []
# remove old captchas # remove old captchas
now = Date.now() while (captcha = captchas[0]) and captcha.time < Date.now()
if captchas.length captchas.shift()
while captchas[0].time < now captchas.push
captchas.shift()
length = captchas.push
challenge: @challenge.firstChild.value challenge: @challenge.firstChild.value
response: response response: response
time: @timeout time: @timeout
$.set 'captchas', captchas $.set 'captchas', captchas
@count length @count captchas.length
@reload() @reload()
load: -> load: ->
@timeout = Date.now() + 25*MINUTE @timeout = Date.now() + 25*MINUTE
@ -1170,12 +1168,10 @@ qr =
else else
# get oldest valid captcha # get oldest valid captcha
captchas = $.get 'captchas', [] captchas = $.get 'captchas', []
if captchas.length # remove old captchas
# remove old captchas while (captcha = captchas[0]) and captcha.time < Date.now()
now = Date.now() captchas.shift()
while (time = captchas[0].time) and time < now if captcha = captchas.shift()
captchas.shift()
if captcha = captchas.shift()
challenge = captcha.challenge challenge = captcha.challenge
response = captcha.response response = captcha.response
else else