CODE

Automatic Anonymous Login after reCAPTCHA v2 Completion

Auto-submit a prefilled login form, to log in an anonymous user, if reCAPTCHA v2 is successfully completed.

v1.0.0

If you require user-submitted module items but don’t require individual logged in users, this workaround can make an anonymous login process a little smoother. Allowing you to simply present the user with the “Prove you’re not a robot” reCAPTCHA and upon successful completion the login form will auto submit and redirect to the configured landing page, without the user needing to fill any other fields and submit the form.

  1. You will need a Secure Zone set up with a dummy CRM contact subscribed to it.

    In the code below we are using a dummy user with the following credentials:
    Email (username): [email protected]
    Password: anonymous

    Adjust these credentials to your own liking if needed, but be sure to also adjust the form code below to match.

  2. Add the below code where you would like to present the reCAPTCHA v2 prompt to the users:

    <!--Treehouse CODE v1.0.0-->
    <form action="/public/api/members/login" method="POST" id="loginForm">
        <input type="hidden" name="Email" value="[email protected]">
        <input type="hidden" name="Password" value="anonymous">
        <div class ="captcha-holder">
            <div class="g-recaptcha"{% if request.request_data.is_mobile == 1 %} data-size="compact"{% endif %} data-sitekey="6Lf2cGcUAAAAABbL4aDrclASNZx9S3uaI9EvpvlI" data-callback="submitForm"></div>
        </div>
        <input type="hidden" name="redirectURL" value="/redirectUrl">
        <br><br>
        <input type="submit" onclick="$(this).closest('form').submit()" value="Submit">
    </form>
    <script>
    var submitForm = function () {
        $("#loginForm").submit();
    }
    </script>

Comments or questions? Head over to the Treepl CMS forum to discuss with the community.