recaptcha issue RRS feed

  • Question

  • User-2060576634 posted

    hi everybody.. I'm using this default register page code structure that can be found in webmatrix templates and i'm trying to set up recaptcha for this registration form.. the recaptcha installation and function looks fine but I don't know why the form gets processed regardless of the recaptcha answer being true or false! any help is appreciated.. here is the code:

    @* Remove this section if you are using bundling *@
    @section Scripts {
        <script src="~/Scripts/jquery.validate.min.js"></script>
        <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    <script src='https://www.google.com/recaptcha/api.js'></script>
        Layout = "~/_SiteLayout.cshtml";
        Page.Title = "register";
        var db = Database.Open("Azmoon");
        // Initialize general page variables
        var email = "";
        var password = "";
        var confirmPassword = "";
        // Setup validation
        Validation.RequireField("email", "some message.");
        Validation.RequireField("password", ".some message");
            Validator.EqualsTo("password", "some message."));
                maxLength: Int32.MaxValue,
                minLength: 6,
                errorMessage: "some message."));
        // If this is a POST request, validate and process data
        if (IsPost) {
            email = Request.Form["email"];
            password = Request.Form["password"];
            confirmPassword = Request.Form["confirmPassword"];
            // Validate the user's captcha answer
             if (!ReCaptcha.Validate("*********************")) {
                 ModelState.AddError("recaptcha", "Captcha response was not correct");
            // If all information is valid, create a new account
            if (Validation.IsValid()) {
                // Insert a new user into the database
                // Check if user already exists
                var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", email);
                if (user == null) {
                    // Insert email into the profile table
                    db.Execute("INSERT INTO UserProfile (Email,NickName,ZoneId,Phone,Date) VALUES (@0,@1,@2,@3,@4)", email,nickname,zoneid,phone,DateTime.Now);
                    // Create and associate a new entry in the membership database.
                    // If successful, continue processing the request
                    try {
                        bool requireEmailConfirmation = !WebMail.SmtpServer.IsEmpty();
                        var token = WebSecurity.CreateAccount(email, password, requireEmailConfirmation);
                        if (requireEmailConfirmation) {
                            var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
                            var confirmationUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Confirm?confirmationCode=" + HttpUtility.UrlEncode(token));
                                 to: email,
                                subject: "Please confirm your account",
                                body: "Your confirmation code is: " + token + ". Visit <a href=\"" + confirmationUrl + "\">" + confirmationUrl + "</a> to activate your account."
                            ); } if (requireEmailConfirmation) { // Thank the user for registering and let them know an email is on its way Response.Redirect("~/Account/Thanks"); } else { // Navigate back to the homepage and exit WebSecurity.Login(email, password); Response.Redirect("~/"); } } catch (System.Web.Security.MembershipCreateUserException e) { ModelState.AddFormError(e.Message); } } else { // User already exists ModelState.AddFormError("some messege."); } } } } <style> .star{ float:right; color:#ff0000; font-weight:bold; margin-left: 5px; } </style> <form method="post"> @AntiForgery.GetHtml() @* If at least one validation error exists, notify the user *@ @Html.ValidationSummary("message", excludeFieldErrors: true, htmlAttributes: null) <fieldset> <legend></legend> <ol> <li class="email"> <div class="star">*</div> <label for="email" @if(!ModelState.IsValidField("email")){<text>class="error-label"</text>}>email</label> <input type="text" id="email" name="email" value="@email" @Validation.For("email") /> @* Write any email validation errors to the page *@ @Html.ValidationMessage("email") </li> <li class="password"> <div class="star">*</div> <label for="password" @if(!ModelState.IsValidField("password")) {<text>class="error-label"</text>}>password</label> <input type="password" id="password" name="password" @Validation.For("password") /> @* Write any password validation errors to the page *@ @Html.ValidationMessage("password") </li> <li class="confirm-password"> <div class="star">*</div> <label for="confirmPassword" @if(!ModelState.IsValidField("confirmPassword")) {<text>class="error-label"</text>}>repeat password</label> <input type="password" id="confirmPassword" name="confirmPassword" @Validation.For("confirmPassword") /> @* Write any password validation errors to the page *@ @Html.ValidationMessage("confirmPassword") </li> <li class="g-recaptcha" data-sitekey="*********************************"> @ReCaptcha.GetHtml("********************************", theme: "white") @Html.ValidationMessage("recaptcha") </li> </ol> <input type="submit" value="submit" /> </fieldset> </form>
    Monday, March 9, 2015 9:44 PM


  • User-2060576634 posted

    looks like the issue has been completely addressed here

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 10, 2015 6:34 AM