Support for new version reCAPTCHA / V2

1 2 3 4 5 > ... >
Posted: December 22, 2014 at 11:57 PM Quote #137436
Do we have any plan to support new version reCAPTCHA ? (V2). The old version is so frustration and hard to resolve in lots of scenarios.

http://techcrunch.com/2014/12/03/googles-recaptcha-mostly-does-away-with-those-annoying-captchas/

Google’s reCAPTCHA (Mostly) Does Away With Those Annoying CAPTCHAs
This post/answer is useful
4
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: December 23, 2014 at 1:57 AM Quote #137440
Hi,

Thanks a lot for suggestion. I've just created a work item
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Regards,
Andrei Mazulnitsyn
Posted: February 03, 2015 at 10:10 AM Quote #139455
Hi,

I have implemented this with reCAPTCHA4net from http://recaptcha4net.codeplex.com/
Demo at shop.getyournet.ch

Step 1
In Nop.Web.Framework, add a reference to the assembly Recaptcha.Web
Also add a reference to System.Net.Http

Step 2
In Nop.Web.Framework > UI > Captcha, change the file HtmlExtensions.cs

using System.IO;
using System.Web.Mvc;
using System.Web.UI;
using Nop.Core.Infrastructure;

namespace Nop.Web.Framework.UI.Captcha
{
    public static class HtmlExtensions
    {
        public static string GenerateCaptcha(this HtmlHelper helper)
        {
            var captchaSettings = EngineContext.Current.Resolve<CaptchaSettings>();

            var theme = !string.IsNullOrEmpty(captchaSettings.ReCaptchaTheme) ? captchaSettings.ReCaptchaTheme : "white";
            var captchaControl = new Recaptcha.Web.UI.Controls.Recaptcha
            {
                ID = "recaptcha",
                ColorTheme = Recaptcha.Web.ColorTheme.Light,
                PublicKey = captchaSettings.ReCaptchaPublicKey,
                PrivateKey = captchaSettings.ReCaptchaPrivateKey
            };

            var htmlWriter = new HtmlTextWriter(new StringWriter());

            captchaControl.RenderControl(htmlWriter);

            return htmlWriter.InnerWriter.ToString();
        }
    }
}


Step 3
In Nop.Web.Framework > UI > Captcha, change the file CaptchaValidatorAttribute.cs

using System.Web.Mvc;
using Nop.Core.Infrastructure;
using System;
using System.Net.Http;
using Newtonsoft.Json.Linq;
using Nop.Services.Tasks;
using System.Threading.Tasks;

namespace Nop.Web.Framework.UI.Captcha
{
    public class CaptchaValidatorAttribute : ActionFilterAttribute
    {
        private const string RESPONSE_FIELD_KEY = "g-reCAPTCHA-response";

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var valid = false;
            var captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
            if (!string.IsNullOrEmpty(captchaResponseValue))
            {
                var captchaSettings = EngineContext.Current.Resolve<CaptchaSettings>();
                if (captchaSettings.Enabled)
                    valid = System.Threading.Tasks.Task.Factory.StartNew(async () => await ValidateResponse(captchaResponseValue, captchaSettings.ReCaptchaPrivateKey).ConfigureAwait(false)).Unwrap().Result;
            }

            //this will push the result value into a parameter in our Action  
            filterContext.ActionParameters["captchaValid"] = valid;

            base.OnActionExecuting(filterContext);
        }

        private async Task<bool> ValidateResponse(string captchaResponseValue, string key)
        {
            var valid = false;
            var uribuilder = new UriBuilder("https://www.google.com/recaptcha/api/siteverify")
            {
                Query = string.Format("secret={0}&response={1}", key, captchaResponseValue)
            };
            using (var httpClient = new HttpClient())
            {
                var async = await httpClient.GetAsync(uribuilder.Uri);
                async.EnsureSuccessStatusCode();
                var readstring = await async.Content.ReadAsStringAsync();
                var resultobject = JObject.Parse(readstring);
                valid = resultobject.Value<bool>("success");
            }
            return valid;
        }
    }
}


Step 4
Compile the project and copy Nop.Web.Framework.dll and Recaptcha.Web.dll to the bin folder of your production site
This post/answer is useful
16
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Best regards
Peter

www.getyournet.ch
Posted: February 04, 2015 at 12:29 AM Quote #139487
Hi Peter,

Great! Thanks a lot for this contribution!
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Regards,
Andrei Mazulnitsyn
Posted: February 04, 2015 at 12:35 AM Quote #139488
gyn wrote:
Hi,

I have implemented this with reCAPTCHA4net from http://recaptcha4net.codeplex.com/
Demo at shop.getyournet.ch
....


Thanks for your tips. That's very helpful. Peter.
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: February 04, 2015 at 4:11 AM Quote #139501
[UPDATE 2015-02-11]
The problem seems to be resolved now:
https://groups.google.com/forum/#!topic/recaptcha/ftk2wHEUXhM

Unfortunately, I found a bug with this implementation and have to raise a warning. It doesn't works on a Windows Phone 8.1 IE11. I will try to find a solution...
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Best regards
Peter

www.getyournet.ch
Posted: April 24, 2015 at 2:48 AM Quote #144004
I'm a bit slow (it usually takes me several tries to get javascript working right so C# is a bit over my head), so what do you mean in step one with:

"In Nop.Web.Framework, add a reference to the assembly Recaptcha.Web
Also add a reference to System.Net.Http"


OR


If you want to make some money off me, make a plugin for this :) I'd buy it.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: April 25, 2015 at 1:19 AM Quote #144052
Aha! Got it figured out, and it is working beautifully!

Thanks a million.

(BTW, if you do come out with a plugin, I'll probably still buy it as thanks for your work and willingness to share, so let me know)
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: July 02, 2015 at 9:53 AM Quote #148098
Any update for Windows Phone 8.1? I am looking into implementing the new reCAPTCHA. Does the new nop3.6 support V2?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
--------------------
Brian Weston
EDCOR Electronics Corporation
www.edcorusa.com
Posted: July 02, 2015 at 8:45 PM Quote #148118
Very nice. How can we change the width to make it responsive? It appears the width is set at around 380px to 385px so it overflows at 320px. Tried modifying Width property in HtmlExtensions.cs. No luck. Tried using the ID in styles.css like #recaptcha{width:100%,border:1 px solid black;}. No luck. All the above does is modify the container the control is in not the control itself. There are other properties in HtmlExtensions.cs that can be changed but just don't know much about them or how to use them.

Googles documentation only shows example if you are rendering the control on an actual page in a form container.

I don't see anything except for size

data-size  size  compact normal  normal  Optional. The size of the widget.

Anyone?? Thanks. G.

Edit: Works fine on IE 11. Didn't test Winphone 8.1.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
1 2 3 4 5 > ... >
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
eCommerce CONFERENCE 2018
Learn more