Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Baldy 20 posts 40 karma points
    Oct 08, 2013 @ 19:07
    Baldy
    0

    Comments not posting

    Umbraco 6.1.1

    uBlogsy 3.0

    uCommentsy 1.0.0.1

    When submitting a comment it just reloads the page.  

    I get a HTTP 200 from fiddler, no error. Same with dev tools.

    How can i work out if its even calling uCommentsyContactFormSurfaceController?

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Oct 23, 2013 @ 13:37
    Anthony Dang
    0

    Hi

    Did you sort out this problem?

    If the page is just releoading it sounds like the controller is not being called.

    Do you have any special routes?

  • Baldy 20 posts 40 karma points
    Oct 23, 2013 @ 16:03
    Baldy
    0

    we never sorted it out, had to drop it and roll our own in the end as we were running out of time.

    There were no special routes.  As you say, it seemed like the controller wasnt being invoked.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 07, 2014 @ 22:25
    Nicholas Westby
    0

    I am having a similar problem, though for mine the page does a post back, and when the page is refreshed there is no indicator that the captcha was incorrect (works fine for correct captchas). I'm guessing this is because Google has moved their API URL for ReCaptcha. See here: https://groups.google.com/d/msg/recaptcha-announce/wf9oREIMnmM/raV_6oNg4kYJ

    The reason I am guessing that is because my Fiddler2 capture of the traffic shows this (I replaced some sensitive information and the extraneous markup):

    http://api.recaptcha.net/challenge?k={UNIQUE_ID}&error=incorrect-captcha-sol
    The document has moved <A HREF="http://www.google.com/recaptcha/api/challenge?k={UNIQUE_ID}&amp;error=incorrect-captcha-sol">here</A>.

    I tried to update http://www.nuget.org/packages/Microsoft.AspNet.Web.Helpers.Mvc/ (where the ReCaptcha functionality is apparently in), but that broke other functionality (I was getting a runtime error on any page with comments due to some version incompatibility between assemblies).

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 07, 2014 @ 23:51
    Nicholas Westby
    0

    Actually, I'm thinking I may be mistaken. Maybe uCommentsy just doens't display an error message when the user gets the ReCaptcha wrong? Based on the code in uCommentsyFormContact.cshtml, it looks like there is some code to handle the case where the query string has a parameter of "success" set to "error". However, it does not redirect to that URL on error. Maybe that's intended for errors other than ReCaptcha mistakes?

    Guess I'll poke around in the source code at https://bitbucket.org/anthonydotnet/ucommentsy to see what may be happening.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 08, 2014 @ 00:29
    Nicholas Westby
    0

    Making some progress. Looking in the action method (uCommentsyContactFormSurfaceController.Post), the only thing that I can see that might indicate a failed captcha is this line:

    if (!ModelState.IsValid) { return CurrentUmbracoPage(); }

    That is at the top of the action method. If that's the case, then any captcha failure would just return the current page, without any indication there was an error. I might be able to use that to test for failed comments, supposing there are not other forms on the page that use model state and supposing I can access ModelState from the view itself. Otherwise, this may require that I recompile uCommentsy and alter the behavior of that action method (e.g., to redirect to the error URL when the captcha fails).

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 08, 2014 @ 00:35
    Nicholas Westby
    0

    Making further progress. I think I was wrong about the above code. This looks like the offending code:

    if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings[Keys.RecaptchaPrivateKey]) && !ReCaptcha.Validate(ConfigurationManager.AppSettings[Keys.RecaptchaPrivateKey])
    && ConfigurationManager.AppSettings[Keys.RecaptchaPrivateKey] != "," && ConfigurationManager.AppSettings[Keys.RecaptchaPrivateKey] != ",")
    {
    // this allows the developer to simply remove recaptcha and the config setting if they dont want it.
    return CurrentUmbracoPage();
    }

    Based on an article I just found (http://www.dotnetcurry.com/showarticle.aspx?ID=611), the ReCaptcha.Validate method is what does the validation. I suppose that method must look at Request.Form for the recaptcha answer (I looked it over before because I only saw the private key being passed as a parameter, but then realized it can access the HttpContext without it being passed as a parameter).

    I can probably just do the same thing to test if the captcha response was valid and take some appropriate action (e.g., display message, redirect user).

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Mar 03, 2014 @ 18:11
    Anthony Dang
    0

    Baldy it dawned on me that perhaps there could be a dll which was conflicting. This happened to me a long time ago. I cant remember what the fix was, although I think it had somehting to do with webapi :/

     

    Nicholas, this may be a silly question, but I assume you have the recaptcha keys in your web.config?

     

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Mar 04, 2014 @ 00:11
    Nicholas Westby
    0

    Hi Anthony,

    Yes, I have ReCaptcha keys in my web.config. I eventually got it working by creating a helper method to detect if the captcha solution was valid or not (I then display an error message to the user if their solution was invalid). I consider this to be a workaround and am not aware of there being a built-in method to ascertain whether or not the uCommentsy post was valid or not. Here is my helper method (note that I also render the "uCommentsyReCaptchaSolutionFlag" input field in the form to be sure it was actually the comment form being submitted):

    // Namespaces.
    using Microsoft.Web.Helpers;
    using System.Configuration;
    using Umbraco.Core;
    using uCommentsyKeys = uCommentsy.BusinessLogic.Constants.Keys;

    ///<summary>
    /// Helps with page comments.
    ///</summary>
    publicclassCommentHelper
    {

        
    ///<summary>
        /// Is the recaptcha solution valid?
        ///</summary>
        ///<returns>
        /// False, if the recaptcha is configured and the solution on postback is invalid; otherwise, true.
        ///</returns>
       public static bool IsRecaptchaSolutionValid()
       {

            
    // Variables.
            var request = System.Web.HttpContext.Current.Request;
            // Don't validate GET requests.
           if ("get".InvariantEquals(request.HttpMethod))
           {
               return true;
           }

            // Don't validate when key isn't configured.
           var privateKey = ConfigurationManager.AppSettings[uCommentsyKeys.RecaptchaPrivateKey];
           if (string.IsNullOrWhiteSpace(privateKey))
           {
               return true;
           }

            
    // Only validate if the uCommentsy form was submitted with the ReCaptcha portion rendered.
            var flag = request.Form["uCommentsyReCaptchaSolutionFlag"];
            if (!"true".InvariantEquals(flag))
           {
               return true;
           }

            
    // Validate solution.
          return ReCaptcha.Validate(privateKey);

       }

    }
  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Mar 05, 2014 @ 12:02
    Anthony Dang
    0

    Interesting. I'll need to look into this.

Please Sign in or register to post replies

Write your reply to:

Draft