use captchas

This commit is contained in:
James Campos 2011-09-02 00:22:51 -07:00
parent 7f1618f977
commit 8496654e65
2 changed files with 53 additions and 11 deletions

View File

@ -1288,7 +1288,6 @@
return ta.focus(); return ta.focus();
}, },
keydown: function(e) { keydown: function(e) {
var captcha, captchas;
if (!(e.keyCode === 13 && this.value)) { if (!(e.keyCode === 13 && this.value)) {
return; return;
} }
@ -1296,19 +1295,45 @@
return; return;
} }
e.preventDefault(); e.preventDefault();
return QR.captchaPush(this);
},
captchaPush: function(el) {
var captcha, captchas;
captcha = QR.captcha; captcha = QR.captcha;
captcha.response = this.value; captcha.response = el.value;
captchas = $.get('captchas', []); captchas = $.get('captchas', []);
captchas.push(captcha); captchas.push(captcha);
$.set('captchas', captchas); $.set('captchas', captchas);
this.value = ''; el.value = '';
Recaptcha.reload(); Recaptcha.reload();
return this.nextSibling.textContent = captchas.length + ' captchas'; return el.nextSibling.textContent = captchas.length + ' captchas';
},
captchaShift: function() {
var captcha, captchas, cutoff;
captchas = $.get('captchas', []);
cutoff = Date.now() - 5 * HOUR + 5 * MINUTE;
while (captcha = captchas.shift()) {
if (captcha.time > cutoff) {
break;
}
}
$.set('captchas', captchas);
return captcha;
}, },
submit: function(e) { submit: function(e) {
var captcha, challenge, el, response;
$('.error', qr.el).textContent = ''; $('.error', qr.el).textContent = '';
$('#challenge', QR.el).value = QR.captcha.challenge; if ((el = $('#recaptcha_response_field', QR.el)).value) {
return $('#response', QR.el).value = $('#recaptcha_response_field', QR.el).value; QR.captchaPush(el);
}
if (!(captcha = captchaShift())) {
alert('You forgot to type in the verification.');
e.preventDefault();
return;
}
challenge = captcha.challenge, response = captcha.response;
$('#challenge', QR.el).value = challenge;
return $('#response', QR.el).value = response;
}, },
sys: function() { sys: function() {
return $.globalEval(function() { return $.globalEval(function() {

View File

@ -1025,18 +1025,35 @@ QR =
return unless e.keyCode is 13 and @value #enter, captcha filled return unless e.keyCode is 13 and @value #enter, captcha filled
return if $('textarea', QR.el).value or $('[type=file]', QR.el).files.length #not blank return if $('textarea', QR.el).value or $('[type=file]', QR.el).files.length #not blank
e.preventDefault() e.preventDefault()
QR.captchaPush @
captchaPush: (el) ->
{captcha} = QR {captcha} = QR
captcha.response = @value captcha.response = el.value
captchas = $.get 'captchas', [] captchas = $.get 'captchas', []
captchas.push captcha captchas.push captcha
$.set 'captchas', captchas $.set 'captchas', captchas
@value = '' el.value = ''
Recaptcha.reload() Recaptcha.reload()
@nextSibling.textContent = captchas.length + ' captchas' el.nextSibling.textContent = captchas.length + ' captchas'
captchaShift: ->
captchas = $.get 'captchas', []
cutoff = Date.now() - 5*HOUR + 5*MINUTE
while captcha = captchas.shift()
if captcha.time > cutoff
break
$.set 'captchas', captchas
captcha
submit: (e) -> submit: (e) ->
$('.error', qr.el).textContent = '' $('.error', qr.el).textContent = ''
$('#challenge', QR.el).value = QR.captcha.challenge if (el = $('#recaptcha_response_field', QR.el)).value
$('#response', QR.el).value = $('#recaptcha_response_field', QR.el).value QR.captchaPush el
if not captcha = captchaShift()
alert 'You forgot to type in the verification.'
e.preventDefault()
return
{challenge, response} = captcha
$('#challenge', QR.el).value = challenge
$('#response', QR.el).value = response
sys: -> sys: ->
$.globalEval -> $.globalEval ->
if node = document.querySelector('table font b')?.firstChild if node = document.querySelector('table font b')?.firstChild