CON-941 - Google reCaptcha 2

Created by Tom 16 Mar 2016, 14:02:07 Updated by Ambert van Unen 16 Jul 2018, 08:45:07

Is duplicated by: CON-1116

Is duplicated by: CON-1389

Subtask of: CON-1390

Add support for new Google reCaptcha 2 ("I'm not a robot"). If this feature does get added it would be good if it could support multiple instances of the reCaptcha on a page. e.g. Two forms both with reCaptcha on a single page.

Cheers, Tom

2 Attachments

Download ReCaptcha2.zip

Comments

Alex Skrypnyk 23 Sep 2016, 11:29:02

It would be great to repace old google reCaptca


Daniel Symonds-Lloyd 27 Feb 2017, 09:09:59

Same feature request as CON-941


Daniel Symonds-Lloyd 01 Mar 2017, 08:02:16

There is a plugin which does this currently: https://our.umbraco.org/projects/collaboration/recaptcha-field-for-umbraco-forms/


Mikulas Tomanka 21 Feb 2018, 11:55:33

Source: https://developers.google.com/recaptcha/docs/faq#what-happens-to-recaptcha-v1

Google recaptcha v1 api is closing down. Currently a percentage of recaptcha v1 hits result in a warning being displayed (in attachment). As this warning is displayed to a percentage of hits, a workaround is to reload the form, until recaptcha doesn't display the warning.

We need to implement recaptcha v2 until 30/3/2018, when the recaptcha v1 apis will stop working.


Sebastiaan Janssen 08 Mar 2018, 23:13:19

A drop-in replacement is available now. It adds a file in App_Code and two view files. If you need the update now then this is an easy replacement. On the form you'll need to replace Recaptcha with Recaptcha2.


Sebastiaan Janssen 09 Mar 2018, 10:33:20

Updated for v4/6 as well


Sebastiaan Janssen 13 Mar 2018, 13:42:52

This will not work for Contour but a similar fieldtype is available for Contour in this forum thread: https://our.umbraco.org/forum/umbraco-pro/contour/63765-Upgrading-ReCaptcha-to-the-Im-not-a-robot-version#comment-215220


Sebastiaan Janssen 13 Mar 2018, 15:24:11

PR: https://github.com/umbraco/Forms/pull/182


Sebastiaan Janssen 13 Mar 2018, 15:25:25

I've updated the drop-in replacement, to be a bit nicer and support both the theme and the size options, so just unzip this into any forms v4/6/7 installation and you should be good to go with the new field.


Robert Copilau 14 Mar 2018, 13:06:50

Code looks good and it works! Merging.


Riddhi 15 Mar 2018, 19:43:29

Hello @sebastiaan, I have Umbraco 6.1.6 site and it has contour form, will this package work for that version?


Sebastiaan Janssen 16 Mar 2018, 07:43:39

This will not work for Contour but a similar fieldtype is available for Contour in this forum thread: https://our.umbraco.org/forum/umbraco-pro/contour/63765-Upgrading-ReCaptcha-to-the-Im-not-a-robot-version#comment-215220


Riddhi 16 Mar 2018, 15:26:41

@sebastiaan Thank you very much


Stan Armstrong 20 Mar 2018, 16:11:46

Hello, I an using Umbraco 7.9 with Forms 7.0 How do I install this great important work?


Sebastiaan Janssen 20 Mar 2018, 16:17:50

@stan246 We haven't released 7.0.1 yet, for now you can use the App_Code workaround above.


Chris Evans 20 Mar 2018, 21:54:02

@sebastiaan Just a few questions about this: Will 7.0.1 replace the v1 recaptcha with v2 as a core field type? Will we need to remove this drop-in code when upgrading to 7.0.1? Do you know if 7.0.1 will be released before March 31?


Chris Evans 20 Mar 2018, 22:10:53

@sebastiaan Also, we noticed a couple issues with the drop-in fix:

  • needed to add using Umbraco.Forms.Core.Attributes; to the App_Code/ReCaptcha2.cs class to get it to compile on runtime

  • the App_Plugins/UmbracoForms/Backoffice/Common/FieldTypes/Recaptcha2.html view was still referencing the old recaptcha image path, instead of /App_Plugins/UmbracoForms/Images/recaptcha2.png


Sebastiaan Janssen 20 Mar 2018, 23:08:30

7.0.1 will have an additional field type which you can replace the current one with. Drop-in code will be fine, doesn't need to be removed, but can be if you want. I unfortunately don't know what the release date will be but yes, I expect it before Mar 31. :)

Cool, I'll update the drop-in replacement tomorrow. Thanks for the test!


Chris Evans 20 Mar 2018, 23:18:06

@sebastiaan Thanks for the quick reply! Appreciate it.


Chris Evans 28 Mar 2018, 21:29:50

@sebastiaan During testing, we found an issue in the Recaptcha2.cs class in App_Code found in this patch.

If the Error message on a Recaptcha field is left blank, and the user does not complete the challenge, an exception gets thrown : System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

This is because of line 77: var error = field.Settings["ErrorMessage"];

We've updated this in our version to be: var error = field.Settings.ContainsKey("ErrorMessage") ? field.Settings["ErrorMessage"] : string.Empty;


Jamie Attwood 30 Apr 2018, 14:44:51

@sebastiaan @cpevans

Just installed this and it is working great - thank you! Installed on Umbraco version 7.6.4 with Forms UmbracoForms.Package.6.0.3. Note the following changes that needed to be made in order to 1) compile the site using JIT and 2) make it actually work (Thank-you Chris Evans for these contributions, I am just summarizing everything here in one post.)

  1. Add using Umbraco.Forms.Core.Attributes; to the App_Code/ReCaptcha2.cs
  2. Upgrade your RecaptchaPublicKey and RecaptchaPrivateKey values in UmbracoForms.config to the values provided by https://www.google.com/recaptcha/ AND make sure you add your domain! It's confusing because they give you the API keys before you actually register domains...
  3. App_Code/ReCaptcha2.cs: Change line 77 to: var error = field.Settings.ContainsKey("ErrorMessage") ? field.Settings["ErrorMessage"] : string.Empty;
  4. Change App_Plugins/UmbracoForms/Backoffice/Common/FieldTypes/Recaptcha2.html view was still referencing the old recaptcha image path, instead of /App_Plugins/UmbracoForms/Images/recaptcha2.png

Cheers,

Jamie


Amir Khan 09 May 2018, 18:36:14

I get an error related to themes not being found on 4.1.4, any ideas?


Ambert van Unen 16 Jul 2018, 08:45:07

Getting an theme error on 4.4.7(forms) Umbraco 7.2.9 aswell Compiler Error Message: CS0246: The type or namespace name 'Setting' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 24: } Line 25: Line 26: [Setting("Theme", prevalues = "light,dark", description = "ReCaptcha v2 theme", view = "dropdownlist")] Line 27: public string Theme { get; set; } Line 28:

Added: using Umbraco.Forms.Core.Attributes; and now it works fine


Priority: Normal

Type: Feature (request)

State: Fixed

Assignee:

Difficulty:

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 7.0.1

Sprint: Sprint 80

Story Points: 3

Cycle: 8