Browse Source

[ADD] website recaptcha reloaded module

pull/1/head
houssine 8 years ago
parent
commit
a7cdc40628
  1. 22
      website_recaptcha_reloaded/__init__.py
  2. 44
      website_recaptcha_reloaded/__openerp__.py
  3. 21
      website_recaptcha_reloaded/models/__init__.py
  4. 36
      website_recaptcha_reloaded/models/res_config.py
  5. BIN
      website_recaptcha_reloaded/static/description/icon.png
  6. 13
      website_recaptcha_reloaded/static/description/index.html
  7. BIN
      website_recaptcha_reloaded/static/description/recaptcha_setting.png
  8. 29
      website_recaptcha_reloaded/views/res_config.xml
  9. 29
      website_recaptcha_reloaded/views/website_view.xml
  10. 49
      website_recaptcha_reloaded/website.py

22
website_recaptcha_reloaded/__init__.py

@ -0,0 +1,22 @@
# -*- 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

44
website_recaptcha_reloaded/__openerp__.py

@ -0,0 +1,44 @@
# -*- 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': True,
'auto_install': False
}

21
website_recaptcha_reloaded/models/__init__.py

@ -0,0 +1,21 @@
# -*- 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

36
website_recaptcha_reloaded/models/res_config.py

@ -0,0 +1,36 @@
# -*- 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 fields, osv
class website_config_settings(osv.osv_memory):
_inherit = 'website.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'),
}

BIN
website_recaptcha_reloaded/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.5 KiB

13
website_recaptcha_reloaded/static/description/index.html

@ -0,0 +1,13 @@
<section class="oe_container">
<div class="oe_row">
<h2 class="oe_slogan">Odoo Website reCAPTCHA Reloaded</h2>
<h4 class="oe_slogan"><a href="https://www.techreceptives.com">By Tech Receptives</a></h4>
<p>
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".
</p>
<div class="oe_row_img oe_centered oe_mt32">
<img class="oe_picture oe_screenshot" src="recaptcha_setting.png" />
</div>
</div>
</section>

BIN
website_recaptcha_reloaded/static/description/recaptcha_setting.png

After

Width: 778  |  Height: 767  |  Size: 105 KiB

29
website_recaptcha_reloaded/views/res_config.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_website_config_settings" model="ir.ui.view">
<field name="name">Website settings</field>
<field name="model">website.config.settings</field>
<field name="inherit_id" ref="website.view_website_config_settings" />
<field name="arch" type="xml">
<group name="social" position="after">
<group string="Google reCAPTCHA Reloaded">
<label for="recaptcha_site_key"/>
<div name="recaptcha_site_key">
<div class="oe_inline">
<field name="recaptcha_site_key" placeholder="Your reCAPTCHA site key"/>
</div>
</div>
<label for="recaptcha_private_key"/>
<div name="recaptcha_private_key">
<div class="oe_inline">
<field name="recaptcha_private_key" placeholder="Your reCAPTCHA private key"/>
</div>
</div>
</group>
</group>
</field>
</record>
</data>
</openerp>

29
website_recaptcha_reloaded/views/website_view.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_editor_recaptcha" name="GoogleRecaptcha" inherit_id="website.layout">
<xpath expr="//body" position="inside">
<script src="https://www.google.com/recaptcha/api.js"></script>
</xpath>
</template>
<record id="view_website_form" model="ir.ui.view">
<field name="name">website.form</field>
<field name="model">website</field>
<field name="inherit_id" ref="website.view_website_form" />
<field name="arch" type="xml">
<div name="social_media" position="after">
<div name="goole_recaptcha">
<separator string="Google reCAPTCHA Reloaded"/>
<group name="social_media">
<field name="recaptcha_site_key" placeholder="Your reCAPTCHA site key"/>
<field name="recaptcha_private_key" placeholder="Your reCAPTCHA private key"/>
</group>
</div>
</div>
</field>
</record>
</data>
</openerp>

49
website_recaptcha_reloaded/website.py

@ -0,0 +1,49 @@
# -*- 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
import requests
import json
class website(osv.osv):
_inherit = 'website'
_columns = {
'recaptcha_site_key': fields.char('reCAPTCHA Site Key'),
'recaptcha_private_key': fields.char('reCAPTCHA Private Key'),
}
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
_defaults = {
'recaptcha_site_key': "6LchkgATAAAAAAdTJ_RCvTRL7_TTcN3Zm_YXB39s",
'recaptcha_private_key': "6LchkgATAAAAADbGqMvbRxHbTnTEkavjw1gSwCng"
}
Loading…
Cancel
Save