Created
November 18, 2020 10:07
-
-
Save sehrishnaz/2ccb82e4ec323ab050bed2c2ecafcb4e to your computer and use it in GitHub Desktop.
Implement Google reCAPTCHA Validation using Python in Odoo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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
For details: https://learnopenerp.blogspot.com/2020/11/implement-google-recaptcha-validation-odoo-python.html