The verify_recaptcha(responseKey, IP) function is used to validate Google reCAPTCHA on the server-side. It sends a request to Google's API to verify the validity of the response key (responseKey) from the client and the user's IP address.verify_recaptcha(responseKey, IP)
Parameters:
- responseKey: The response key from the client (sent from the form when the user completes reCAPTCHA).
- IP: The user's IP address.
- Add the secret key to the site's settings.
- The request includes:
- secret (the site's secret key, provided by Google).
- response (the responseKey value).
- remoteip (the IP value, optional).
- The API returns a JSON response with a success field:
- true: Verification successful.
- false: Verification failed, with error codes (if any).
{% if request_method()|lower == 'post' %}
{% set recaptcha = get_post('g-recaptcha-response') %}
{% if recaptcha is null %}
<p class="alert alert-danger">Please complete the robot verification.</p>
{% elseif verify_recaptcha(recaptcha, ip()) %}
{% set user = get_data_by_id('users', 1).data %}
{% set input_nick = get_post('nick')|lower %}
{% set input_pass = get_post('pass')|lower %}
{% if user['nick'] == input_nick and user['pass'] == md5(input_pass) %}
{% do set_cookie('token', user['pass']) %}
{{ redirect('/manager') }}
{% else %}
<p class="alert alert-warning">
Invalid login credentials. Please try again.
</p>
{% endif %}
{% else %}
<p class="alert alert-danger">
Verification failed. Please complete the robot verification.
</p>
{% endif %}
{% endif %}