Implementing Google's new reCAPTCHA

Topics: Customizing Orchard
Dec 9, 2014 at 8:57 PM
I'm trying to implement google's new reCAPTCHA in Orchard but am running into problems with the verification proccess. I'm using the antispam module as a basis to work off of except I have created my implementation as a field instead of a content part. The antispam module uses a viewmodel to grab the response from the reCAPTCHA and sends that in a request to google's verification api when the submit button is hit. I tried doing the same with my implementation but the response is put in a field with the name: "g-recaptcha-response" which causes a problem because the view model can't match with the name of the field. Is there a way I could instead grab the parameters passed in the action when the submit button is clicked instead of trying to grab them using a viewmodel?
Dec 10, 2014 at 12:44 AM
What's wrong with the built-in reCaptcha support?
Dec 11, 2014 at 6:45 PM
Sorry, nothing is wrong with the built-int reCaptcha support. We just need to build in the new one Google just released.
Dec 15, 2014 at 7:32 PM
What changes does it require? Why not contribute those changes to the core?
Dec 16, 2014 at 2:17 AM
I had to rework the method used to request Google's API as their new version of reCAPTCHA works differently and I created a module for binding aliases in models because the new API uses a textarea with the name g-recaptcha-response and I needed to be able to bind that to a variable in my model so I could access it in my driver to include the response in the API request. How do I contribute my changes to the core? I built the new reCAPTCHA in a separate module from the antispam module but I could change the antispam module to utilize the new google reCAPTCHA instead of having a separate module. I would probably still leave the module for binding aliases separate however.
Dec 28, 2014 at 1:48 AM
How do I contribute my changes to the core?
You submit a pull request.
Dec 28, 2014 at 10:02 PM
okay, is this something that would be helpful for you guys?
Feb 18, 2015 at 1:17 PM
Hi There

Would it be possible for you to share the module you created as I have to do the same thing.

Im on 1.7.2 the capture seems to be working but the contentitem still gets created even when the capture fails.
Feb 27, 2015 at 9:24 PM

I have uploaded my modules for the new Google reCAPTCHA to the gallery, but you will need to make some changes if you are using a version of Orchard prior to 1.8, which you are. Download the versions of the reCAPTCHA module and Alias Model Binder module that specify they are for the current version of Orchard, these should be version 1.0 for both of the modules. Next you will need to install them on a copy of Orchard 1.8 and change the Module.txt file for both to specify Orchard version 1.7 or prior (currently it is set to 1.8 which means it won't install on a version of Orchard prior to 1.8). After you make the changes you can package the modules and install them on your Orchard site. Hope this helps.
Mar 21, 2015 at 8:44 PM
Edited Mar 22, 2015 at 12:34 AM

I've been pretty busy with school and work the past several months but am revisiting the possibility of contributing my changes that implement the new Google reCAPTCHA. I have a couple of questions first:
  1. Should I leave recaptcha as a content part (that is how it is currently set up) as opposed to a field (which is how I chose to implement it)?
  2. Is there another method of handling the binding issues that would be preferred over the alias model binder I created?
  3. If not, should I keep the alias model binder service separate from the anti-spam module or combine them?
I was thinking of building this for Orchard 1.9 as I have already set it up to work as a form element as well. Would it be better to fork 1.x or to fork 1.9-int?


Edit: I found a method that removes the need for an alias model binder. Instead of using a viewmodel to capture the value of the g-recaptcha-response field it is possible to use context.Request.Form["g-recaptcha-response"] which removes the need for an alias model binder. However, it would seem to me that using the context.Request.Form method removes the usefulness of the if statement:
 if(updater.TryUpdateModel(submitViewModel, String.Empty, null, null)) {
since the viewmodel is no longer being used. I would imagine this if statement stops the recaptcha from trying to validate before a user has interacted with it (changing the value of the response). Should this if statement be left in despite the viewmodel not being used, or would it be better to remove it? I have tested both and didn't notice a difference either way.
Mar 23, 2015 at 6:28 PM
If the viewmodel is not being used, not even for validation, then it should go.