79325491

Date: 2025-01-03 04:24:28
Score: 0.5
Natty:
Report link

Here we discribed about How to implement recaptcha in odoo!

Adding Google reCAPTCHA to your Odoo system can enhance security by preventing automated bots from abusing your forms.

Install Required Dependencies Ensure you have the necessary Python libraries installed:

Customize the Odoo Form Edit the form where you want to integrate reCAPTCHA (e.g., contact us, signup form). Add the reCAPTCHA widget to your form:

Verify reCAPTCHA on the Server Side Create a method in your Odoo server to verify the reCAPTCHA response.

Add the following logic to your Python controller:

import requests

from odoo.http import request

class MyController(http.Controller):

@http.route('/submit_form', type='http', auth="public", methods=['POST'], website=True)

def submit_form(self, **kwargs):

    recaptcha_response = kwargs.get('g-recaptcha-response')

    secret_key = 'your-secret-key'

    verify_url = 'https://www.google.com/recaptcha/api/siteverify'
    payload = {
        'secret': secret_key,
        'response': recaptcha_response
    }
    response = requests.post(verify_url, data=payload)
    result = response.json()
    if result.get('success'):
        # Process the form data
        return request.render('your_module.template_thank_you')
    else:
        # Handle invalid reCAPTCHA
        return request.render('your_module.template_error', {'error': 'Invalid reCAPTCHA.'})

Update the form action to submit to your defined route (/submit_form in this case).

By implementing reCAPTCHA in Odoo, you protect your platform from spam and malicious activity while maintaining a user-friendly experience.

Regards

Webkul

Reasons:
  • Blacklisted phrase (1): Regards
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Spammer