From 9b5be19d93a372a8f968ac4da2717bf87a10fb26 Mon Sep 17 00:00:00 2001 From: Alex Yue Date: Sun, 25 Jan 2015 14:27:33 -0500 Subject: [PATCH 1/2] Upgraded to support reCAPTCHA v2 --- README.md | 12 ++++++++---- client/client.html | 15 ++++++++++++++- client/client.js | 12 ++---------- package.js | 8 ++++---- server/server.js | 18 ++++++++---------- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 15d9556..8ff5213 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,22 @@ -# Meteor reCAPTCHA -Google's reCAPTCHA is a free CAPTCHA service that protects your site against spam, malicious registrations and other forms of attacks where computers try to disguise themselves as a human. In addition to protecting your site, reCAPTCHA also helps digitize old books and newspapers. +# Meteor reCAPTCHA v2 +This is an implementation of the Google reCAPTCHA v2 API (i.e. "I'm not a robot") for Meteor sites. reCAPTCHA is a free CAPTCHA service provided by Google that authenticates real users while attempting to block bots. reCAPTCHA is at https://developers.google.com/recaptcha/ -Package made with the help of this [StackOverflow question](http://stackoverflow.com/questions/22253196/working-example-of-recaptcha-in-meteor). +Package is an upgraded version of Meteor-reCAPTCHA provided by Altapp (https://github.com/Altapp/Meteor-reCAPTCHA). ## Installation ``` sh -$ meteor add altapp:recaptcha +$ meteor add yuea:recaptcha ``` ## Setup +### Obtain reCAPTCHA Keys From Google + +Register at https://www.google.com/recaptcha/admin to obtain your private and public key needed for reCAPTCHA to function. + ###On The Client Add your reCAPTCHA public key (from Google) to the package. Do this in client-side code. diff --git a/client/client.html b/client/client.html index edef6e1..fe67d29 100644 --- a/client/client.html +++ b/client/client.html @@ -1,3 +1,16 @@ \ No newline at end of file diff --git a/client/client.js b/client/client.js index 92f1a91..6b2b15e 100644 --- a/client/client.js +++ b/client/client.js @@ -9,14 +9,6 @@ reCAPTCHA = { Template.reCAPTCHA.rendered = function() { - - $.getScript('//www.google.com/recaptcha/api/js/recaptcha_ajax.js', function() { - Recaptcha.create(reCAPTCHA.settings.publickey, 'rendered-captcha-container', { - theme: reCAPTCHA.settings.theme, - callback: function() { - return; - } - }); + $.getScript('https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit', function() { }); - -} +} \ No newline at end of file diff --git a/package.js b/package.js index 522e61b..7d267f9 100755 --- a/package.js +++ b/package.js @@ -1,8 +1,8 @@ Package.describe({ - name: "altapp:recaptcha", - summary: "Form bot protection for Meteor.", - git: "https://github.com/Altapp/Meteor-reCAPTCHA.git", - version: "1.2.0" + name: "yuea:recaptcha", + summary: "Google recAPTCHA v2 package for Meteor", + git: "https://github.com/yuea/Meteor-reCAPTCHA.git", + version: "2.0.0" }); Package.onUse(function(api) { diff --git a/server/server.js b/server/server.js index 12bb7f0..8baf8fb 100644 --- a/server/server.js +++ b/server/server.js @@ -3,24 +3,22 @@ reCAPTCHA = { config: function(settings) { return _.extend(this.settings, settings); }, - verifyCaptcha: function(clientIP, data) { + verifyCaptcha: function(recaptchaResponse, clientIP) { var captcha_data = { - privatekey: this.settings.privatekey, + secret: this.settings.privatekey, // for prod: process.env.RECAPTCHA_PRIVATE_KEY, remoteip: clientIP, - challenge: data.captcha_challenge_id, - response: data.captcha_solution + response: recaptchaResponse }; var serialized_captcha_data = - 'privatekey=' + captcha_data.privatekey + + 'secret=' + captcha_data.secret + '&remoteip=' + captcha_data.remoteip + - '&challenge=' + captcha_data.challenge + '&response=' + captcha_data.response; var captchaVerificationResult = null; var success, parts; // used to process response string try { - captchaVerificationResult = HTTP.call("POST", "http://www.google.com/recaptcha/api/verify", { + captchaVerificationResult = HTTP.call("POST", "https://www.google.com/recaptcha/api/siteverify", { content: serialized_captcha_data.toString('utf8'), headers: { 'Content-Type': 'application/x-www-form-urlencoded', @@ -36,12 +34,12 @@ reCAPTCHA = { } parts = captchaVerificationResult.content.split('\n'); - success = parts[0]; + success = parts[1]; - if (success !== 'true') { + if (success.indexOf('true') < 0) { return { 'success': false, - 'error': 'Entered Text Does Not Match' + 'error': 'reCAPTCHA verification failed' }; } From e7cb7110219907e1965795546c6422306afe65e6 Mon Sep 17 00:00:00 2001 From: Alex Yue Date: Mon, 26 Jan 2015 16:10:32 -0500 Subject: [PATCH 2/2] Updated readme --- .versions | 26 ++++++++++++++++++++++++++ README.md | 15 ++++++--------- package.js | 4 ++-- 3 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 .versions diff --git a/.versions b/.versions new file mode 100644 index 0000000..c5b04ee --- /dev/null +++ b/.versions @@ -0,0 +1,26 @@ +ayue:recaptcha@2.0.0 +base64@1.0.2 +blaze@2.0.4 +blaze-tools@1.0.2 +deps@1.0.6 +ejson@1.0.5 +geojson-utils@1.0.2 +handlebars@1.0.2 +html-tools@1.0.3 +htmljs@1.0.3 +http@1.0.10 +id-map@1.0.2 +jquery@1.11.3 +json@1.0.2 +meteor@1.1.4 +minifiers@1.1.3 +minimongo@1.0.6 +observe-sequence@1.0.4 +ordered-dict@1.0.2 +random@1.0.2 +reactive-var@1.0.4 +spacebars-compiler@1.0.4 +templating@1.0.11 +tracker@1.0.5 +underscore@1.0.2 +url@1.0.3 diff --git a/README.md b/README.md index 8ff5213..e367038 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Package is an upgraded version of Meteor-reCAPTCHA provided by Altapp (https://g ## Installation ``` sh -$ meteor add yuea:recaptcha +$ meteor add ayue:recaptcha ``` ## Setup @@ -71,12 +71,9 @@ Template.myTemplate.events({ }; //get the captcha data - var captchaData = { - captcha_challenge_id: Recaptcha.get_challenge(), - captcha_solution: Recaptcha.get_response() - }; + var recaptchaResponse = grecaptcha.getResponse(); - Meteor.call('formSubmissionMethod', formData, captchaData, function(error, result) { + Meteor.call('formSubmissionMethod', formData, recaptchaResponse, function(error, result) { if (error) { console.log('There was an error: ' + error.reason); } else { @@ -89,13 +86,13 @@ Template.myTemplate.events({ ###On The Server -In the server method, pass the captcha data and the user's IP address to `reCAPTCHA.verifyCaptcha(clientIP, captchaData)` to verify that the user entered the correct text. +In the server method, pass the captcha data and the user's IP address to `reCAPTCHA.verifyCaptcha(recaptchaResponse, clientIP)` to verify that the user entered the correct text. ``` javascript Meteor.methods({ - formSubmissionMethod: function(formData, captchaData) { + formSubmissionMethod: function(formData, recaptchaResponse) { - var verifyCaptchaResponse = reCAPTCHA.verifyCaptcha(this.connection.clientAddress, captchaData); + var verifyCaptchaResponse = reCAPTCHA.verifyCaptcha(recaptchaResponse, this.connection.clientAddress); if (!verifyCaptchaResponse.success) { console.log('reCAPTCHA check failed!', verifyCaptchaResponse); diff --git a/package.js b/package.js index 7d267f9..5c111dd 100755 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ - name: "yuea:recaptcha", - summary: "Google recAPTCHA v2 package for Meteor", + name: "ayue:recaptcha", + summary: "Google reCAPTCHA v2 package for Meteor", git: "https://github.com/yuea/Meteor-reCAPTCHA.git", version: "2.0.0" });