You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Tech-Receptives Solutions Pvt. Ltd.
  5. # Copyright (C)2004-TODAY Tech Receptives(<https://www.techreceptives.com>)
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import osv, fields
  22. import requests
  23. import json
  24. class website(osv.osv):
  25. _inherit = 'website'
  26. _columns = {
  27. 'recaptcha_site_key': fields.char('reCAPTCHA Site Key'),
  28. 'recaptcha_private_key': fields.char('reCAPTCHA Private Key'),
  29. }
  30. def is_captcha_valid(self, cr, uid, ids, response, context={}):
  31. for website in self.browse(cr, uid, ids, context=context):
  32. get_res = {'secret': website.recaptcha_private_key,'response': response}
  33. try:
  34. response = requests.get('https://www.google.com/recaptcha/api/siteverify', params=get_res)
  35. except Exception,e:
  36. raise osv.except_osv(('Invalid Data!'),("%s.")%(e))
  37. res_con = json.loads(response.content)
  38. if res_con.has_key('success') and res_con['success']:
  39. return True
  40. return False
  41. _defaults = {
  42. 'recaptcha_site_key': "6LchkgATAAAAAAdTJ_RCvTRL7_TTcN3Zm_YXB39s",
  43. 'recaptcha_private_key': "6LchkgATAAAAADbGqMvbRxHbTnTEkavjw1gSwCng"
  44. }