houssine
5 years ago
8 changed files with 134 additions and 186 deletions
-
26website_recaptcha_reloaded/__init__.py
-
26website_recaptcha_reloaded/__manifest__.py
-
45website_recaptcha_reloaded/__openerp__.py
-
24website_recaptcha_reloaded/models/__init__.py
-
58website_recaptcha_reloaded/models/res_config.py
-
41website_recaptcha_reloaded/views/res_config.xml
-
8website_recaptcha_reloaded/views/website_view.xml
-
76website_recaptcha_reloaded/website.py
@ -1,22 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Tech-Receptives Solutions Pvt. Ltd. |
|||
# Copyright (C)2004-TODAY Tech Receptives(<https://www.techreceptives.com>) |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
import website |
|||
import models |
|||
# Copyright 2004 Tech-Receptives Solutions Pvt. Ltd. |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|||
from . import website |
|||
from . import models |
@ -0,0 +1,26 @@ |
|||
# Copyright 2004 Tech-Receptives Solutions Pvt. Ltd. |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|||
{ |
|||
'name': 'Website reCAPTCHA Reloaded', |
|||
'version': '12.0.0.1', |
|||
'category': 'Website', |
|||
'depends': ['website'], |
|||
'author': 'Tech Receptives', |
|||
'license': 'AGPL-3', |
|||
'website': 'https://www.techreceptives.com', |
|||
'description': """ |
|||
Odoo Website reCAPTCHA Reloaded |
|||
================================ |
|||
This modules allows you to integrate Google reCAPTCHA v2.0 to your website |
|||
forms. You can configure your Google reCAPTCHA site and public keys |
|||
in "Settings" -> "Website Settings" |
|||
|
|||
You will need to install various website_<module>_recaptcha modules |
|||
to use it in your various pages. |
|||
""", |
|||
'data': [ |
|||
'views/website_view.xml', |
|||
'views/res_config.xml', |
|||
], |
|||
'installable': True, |
|||
} |
@ -1,45 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Tech-Receptives Solutions Pvt. Ltd. |
|||
# Copyright (C)2004-TODAY Tech Receptives(<https://www.techreceptives.com>) |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
{ |
|||
'name': 'Website reCAPTCHA Reloaded', |
|||
'version': '1.0', |
|||
'category': 'Website', |
|||
'depends': ['website'], |
|||
'author': 'Tech Receptives', |
|||
'license': 'AGPL-3', |
|||
'website': 'https://www.techreceptives.com', |
|||
'description': """ |
|||
Odoo Website reCAPTCHA Reloaded |
|||
================================ |
|||
This modules allows you to integrate Google reCAPTCHA v2.0 to your website |
|||
forms. You can configure your Google reCAPTCHA site and public keys |
|||
in "Settings" -> "Website Settings" |
|||
|
|||
You will need to install various website_<module>_recaptcha modules |
|||
to use it in your various pages. |
|||
""", |
|||
'data': [ |
|||
'views/website_view.xml', |
|||
'views/res_config.xml', |
|||
], |
|||
'installable': False, |
|||
'auto_install': False |
|||
} |
@ -1,21 +1,3 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Tech-Receptives Solutions Pvt. Ltd. |
|||
# Copyright (C)2004-TODAY Tech Receptives(<https://www.techreceptives.com>) |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
import res_config |
|||
# Copyright 2004 Tech-Receptives Solutions Pvt. Ltd. |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|||
from . import res_config |
@ -1,36 +1,32 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Tech-Receptives Solutions Pvt. Ltd. |
|||
# Copyright (C)2004-TODAY Tech Receptives(<https://www.techreceptives.com>) |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
# Copyright 2019 Simone Orsi - Camptocamp SA |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) |
|||
|
|||
from openerp.osv import fields, osv |
|||
from odoo import api, fields, models |
|||
|
|||
|
|||
class website_config_settings(osv.osv_memory): |
|||
_inherit = 'website.config.settings' |
|||
class website_config_settings(models.TransientModel): |
|||
_inherit = 'res.config.settings' |
|||
|
|||
_columns = { |
|||
'recaptcha_site_key': fields.related( |
|||
'website_id', 'recaptcha_site_key', type="char", |
|||
string='reCAPTCHA site Key'), |
|||
'recaptcha_private_key': fields.related( |
|||
'website_id', 'recaptcha_private_key', type="char", |
|||
string='reCAPTCHA Private Key'), |
|||
} |
|||
recaptcha_key_site = fields.Char( |
|||
related='website_id.recaptcha_key_site', |
|||
readonly=False, |
|||
) |
|||
recaptcha_key_secret = fields.Char( |
|||
related='website_id.recaptcha_key_secret', |
|||
readonly=False, |
|||
) |
|||
has_google_recaptcha = fields.Boolean( |
|||
'Google reCaptcha', |
|||
compute='_compute_has_google_recaptcha', |
|||
inverse='_inverse_has_google_recaptcha', |
|||
readonly=False, |
|||
) |
|||
|
|||
@api.depends('website_id') |
|||
def _compute_has_google_recaptcha(self): |
|||
self.has_google_recaptcha = bool(self.recaptcha_key_site) |
|||
|
|||
def _inverse_has_google_recaptcha(self): |
|||
if not self.has_google_recaptcha: |
|||
self.recaptcha_key_site = False |
|||
self.recaptcha_key_secret = False |
@ -1,49 +1,43 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Tech-Receptives Solutions Pvt. Ltd. |
|||
# Copyright (C)2004-TODAY Tech Receptives(<https://www.techreceptives.com>) |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from openerp.osv import osv, fields |
|||
# Copyright 2019 Simone Orsi - Camptocamp SA |
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|||
|
|||
from odoo import api, fields, models, _ |
|||
from odoo.exceptions import ValidationError |
|||
import requests |
|||
import json |
|||
|
|||
class website(osv.osv): |
|||
URL = 'https://www.google.com/recaptcha/api/siteverify' |
|||
|
|||
|
|||
class Website(models.Model): |
|||
_inherit = 'website' |
|||
|
|||
_columns = { |
|||
'recaptcha_site_key': fields.char('reCAPTCHA Site Key'), |
|||
'recaptcha_private_key': fields.char('reCAPTCHA Private Key'), |
|||
recaptcha_key_site = fields.Char() |
|||
recaptcha_key_secret = fields.Char() |
|||
|
|||
@api.model |
|||
def _get_error_message(self, errorcode=None): |
|||
mapping = { |
|||
'missing-input-secret': _('The secret parameter is missing.'), |
|||
'invalid-input-secret': |
|||
_('The secret parameter is invalid or malformed.'), |
|||
'missing-input-response': _('The response parameter is missing.'), |
|||
'invalid-input-response': |
|||
_('The response parameter is invalid or malformed.'), |
|||
} |
|||
return mapping.get(errorcode, _('There was a problem with ' |
|||
'the captcha entry.')) |
|||
|
|||
def is_captcha_valid(self, response): |
|||
get_res = {'secret': self.recaptcha_key_secret, |
|||
'response': response} |
|||
|
|||
def is_captcha_valid(self, cr, uid, ids, response, context={}): |
|||
for website in self.browse(cr, uid, ids, context=context): |
|||
get_res = {'secret': website.recaptcha_private_key,'response': response} |
|||
try: |
|||
response = requests.get('https://www.google.com/recaptcha/api/siteverify', params=get_res) |
|||
except Exception,e: |
|||
raise osv.except_osv(('Invalid Data!'),("%s.")%(e)) |
|||
res_con = json.loads(response.content) |
|||
if res_con.has_key('success') and res_con['success']: |
|||
return True |
|||
return False |
|||
res = requests.post(URL, data=get_res).json() |
|||
|
|||
_defaults = { |
|||
'recaptcha_site_key': "6LchkgATAAAAAAdTJ_RCvTRL7_TTcN3Zm_YXB39s", |
|||
'recaptcha_private_key': "6LchkgATAAAAADbGqMvbRxHbTnTEkavjw1gSwCng" |
|||
} |
|||
error_msg = "\n".join(self._get_error_message(error) |
|||
for error in res.get('error-codes', [])) |
|||
if error_msg: |
|||
raise ValidationError(error_msg) |
|||
|
|||
if not res.get('success'): |
|||
raise ValidationError(self._get_error_message()) |
|||
return True |
Write
Preview
Loading…
Cancel
Save
Reference in new issue