Skip to content

Instantly share code, notes, and snippets.

@sehrishnaz
Created November 18, 2020 10:07
Show Gist options
  • Save sehrishnaz/2ccb82e4ec323ab050bed2c2ecafcb4e to your computer and use it in GitHub Desktop.
Save sehrishnaz/2ccb82e4ec323ab050bed2c2ecafcb4e to your computer and use it in GitHub Desktop.
Implement Google reCAPTCHA Validation using Python in Odoo
# -*- coding: utf-8 -*-
from openerp import http
from openerp.http import Controller, route, request
import json
import requests
class Google_Recaptcha(http.Controller):
@http.route('/google_recaptcha_in_odoo/', type='http', auth='public', website=True)
def google_recaptcha(self, redirect=None, **kw):
if request.httprequest.method == 'POST':
client_key = kw['g-recaptcha-response']
secret_key = 'your_secretkey_goes_here'
captcha_data = {
'secret': secret_key,
'response': client_key
}
r = requests.post('https://www.google.com/recaptcha/api/siteverify', data=captcha_data)
response = json.loads(r.text)
verify = response['success']
if verify:
# your logic goes here
return request.render('module_name.your_form_template', {
'key_1': 'Test',
'key_2': kw,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment