summaryrefslogtreecommitdiff
path: root/addons/google_base_account
diff options
context:
space:
mode:
authorVidhin Mehta <vme@tinyerp.com>2013-08-23 10:36:02 +0530
committerVidhin Mehta <vme@tinyerp.com>2013-08-23 10:36:02 +0530
commit75ddd5ccbec73c4a671b6a74efaa3d41dc2ea2db (patch)
tree50ed3620df15e8533760f5d47e754a1d39c1e856 /addons/google_base_account
parent42f27a15275effd9c43dfe99e32c395ca6b3fd8a (diff)
parenta7f4b6aaa0359d12046e81183417c24f093cd7c3 (diff)
[MERGE]Trunk.
bzr revid: vme@tinyerp.com-20130823050602-33bqv07e7g8dhv7x
Diffstat (limited to 'addons/google_base_account')
-rw-r--r--addons/google_base_account/__init__.py1
-rw-r--r--addons/google_base_account/__openerp__.py5
-rw-r--r--addons/google_base_account/google_base_account.py52
-rw-r--r--addons/google_base_account/google_base_account_data.xml9
-rw-r--r--addons/google_base_account/google_base_account_view.xml20
-rw-r--r--addons/google_base_account/wizard/__init__.py25
-rw-r--r--addons/google_base_account/wizard/google_login.py85
-rw-r--r--addons/google_base_account/wizard/google_login_view.xml35
8 files changed, 54 insertions, 178 deletions
diff --git a/addons/google_base_account/__init__.py b/addons/google_base_account/__init__.py
index e1a476431af..44a5aabe277 100644
--- a/addons/google_base_account/__init__.py
+++ b/addons/google_base_account/__init__.py
@@ -20,7 +20,6 @@
##############################################################################
import google_base_account
-import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/google_base_account/__openerp__.py b/addons/google_base_account/__openerp__.py
index b4d996f2807..99678d2785d 100644
--- a/addons/google_base_account/__openerp__.py
+++ b/addons/google_base_account/__openerp__.py
@@ -30,10 +30,9 @@ The module adds google user in res user.
""",
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
- 'depends': ['base'],
+ 'depends': ['base_setup'],
'data': [
- 'google_base_account_view.xml',
- 'wizard/google_login_view.xml',
+ 'google_base_account_data.xml',
],
'demo': [],
'installable': True,
diff --git a/addons/google_base_account/google_base_account.py b/addons/google_base_account/google_base_account.py
index 06e5643344c..50fbf233ce6 100644
--- a/addons/google_base_account/google_base_account.py
+++ b/addons/google_base_account/google_base_account.py
@@ -19,14 +19,48 @@
#
##############################################################################
-from openerp.osv import fields,osv
-
-class res_users(osv.osv):
- _inherit = "res.users"
- _columns = {
- 'gmail_user': fields.char('Username', size=64,),
- 'gmail_password': fields.char('Password', size=64),
- }
+from openerp.osv import osv
+from openerp import SUPERUSER_ID
+from openerp.tools.translate import _
-# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
+import urllib
+import urllib2
+import simplejson
+
+
+class google_service(osv.osv_memory):
+ _name = 'google.service'
+
+ def generate_refresh_token(self, cr, uid, service, authorization_code, context=None):
+ if authorization_code:
+ ir_config = self.pool['ir.config_parameter']
+ client_id = ir_config.get_param(cr, SUPERUSER_ID, 'google_%s_client_id' % service)
+ client_secret = ir_config.get_param(cr, SUPERUSER_ID, 'google_%s_client_secret' % service)
+ redirect_uri = ir_config.get_param(cr, SUPERUSER_ID, 'google_redirect_uri')
+ #Get the Refresh Token From Google And store it in ir.config_parameter
+ headers = {"Content-type": "application/x-www-form-urlencoded"}
+ data = dict(code=authorization_code, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, grant_type="authorization_code")
+ data = urllib.urlencode(data)
+ try:
+ req = urllib2.Request("https://accounts.google.com/o/oauth2/token", data, headers)
+ content = urllib2.urlopen(req).read()
+ except urllib2.HTTPError:
+ raise self.pool.get('res.config.settings').get_config_warning(cr, _("Something went wrong during your token generation. Maybe your Authorization Code is invalid or already expired"), context=context)
+
+ content = simplejson.loads(content)
+ return content.get('refresh_token')
+
+ def _get_google_token_uri(self, cr, uid, service, scope, context=None):
+ ir_config = self.pool['ir.config_parameter']
+ params = {
+ 'scope': scope,
+ 'redirect_uri': ir_config.get_param(cr, SUPERUSER_ID, 'google_redirect_uri'),
+ 'client_id': ir_config.get_param(cr, SUPERUSER_ID, 'google_%s_client_id' % service),
+ 'response_type': 'code',
+ 'client_id': ir_config.get_param(cr, SUPERUSER_ID, 'google_%s_client_id' % service),
+ }
+ uri = 'https://accounts.google.com/o/oauth2/auth?%s' % urllib.urlencode(params)
+ return uri
+
+# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/google_base_account/google_base_account_data.xml b/addons/google_base_account/google_base_account_data.xml
new file mode 100644
index 00000000000..c6748df7dc9
--- /dev/null
+++ b/addons/google_base_account/google_base_account_data.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<openerp>
+ <data noupdate="1">
+ <record id="config_google_redirect_uri" model="ir.config_parameter">
+ <field name="key">google_redirect_uri</field>
+ <field name="value">urn:ietf:wg:oauth:2.0:oob</field>
+ </record>
+ </data>
+</openerp> \ No newline at end of file
diff --git a/addons/google_base_account/google_base_account_view.xml b/addons/google_base_account/google_base_account_view.xml
deleted file mode 100644
index 8613582692f..00000000000
--- a/addons/google_base_account/google_base_account_view.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0"?>
-<openerp>
- <data>
- <record id="view_users_gogole_form" model="ir.ui.view">
- <field name="name">res.users.google.form1</field>
- <field name="model">res.users</field>
- <field name="inherit_id" ref="base.view_users_form"/>
- <field name="arch" type="xml">
- <xpath expr="//notebook" position="inside">
- <page string="Synchronization">
- <group string="Google Account" colspan="4">
- <field name="gmail_user"/>
- <field name="gmail_password" password="True"/>
- </group>
- </page>
- </xpath>
- </field>
- </record>
- </data>
-</openerp>
diff --git a/addons/google_base_account/wizard/__init__.py b/addons/google_base_account/wizard/__init__.py
deleted file mode 100644
index a6b9c644a1e..00000000000
--- a/addons/google_base_account/wizard/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
-#
-# 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 google_login
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
diff --git a/addons/google_base_account/wizard/google_login.py b/addons/google_base_account/wizard/google_login.py
deleted file mode 100644
index 1771d99b51e..00000000000
--- a/addons/google_base_account/wizard/google_login.py
+++ /dev/null
@@ -1,85 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
-#
-# 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
-from openerp.tools.translate import _
-try:
- import gdata.contacts.service
- import gdata.contacts.client
- import gdata.calendar.service
-except ImportError:
- raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
-
-class google_login(osv.osv_memory):
- _description ='Google Contact'
- _name = 'google.login'
- _columns = {
- 'user': fields.char('Google Username', size=64, required=True),
- 'password': fields.char('Google Password', size=64),
- }
-
- def google_login(self, user, password, type='', context=None):
- if type == 'group':
- gd_client = gdata.contacts.service.ContactsService()
- elif type == 'contact':
- gd_client = gdata.contacts.service.ContactsService()
- elif type == 'calendar':
- gd_client = gdata.calendar.service.CalendarService()
- elif type =='docs_client':
- gd_client = gdata.docs.client.DocsClient()
- else:
- gd_client = gdata.contacts.service.ContactsService()
- try:
- gd_client.ClientLogin(user, password, gd_client.source)
- except Exception:
- return False
- return gd_client
-
-
- def default_get(self, cr, uid, fields, context=None):
- res = super(google_login, self).default_get(cr, uid, fields, context=context)
- user_obj = self.pool.get('res.users').browse(cr, uid, uid)
- if 'user' in fields:
- res.update({'user': user_obj.gmail_user})
- if 'password' in fields:
- res.update({'password': user_obj.gmail_password})
- return res
-
- def login(self, cr, uid, ids, context=None):
- data = self.read(cr, uid, ids)[0]
- user = data['user']
- password = data['password']
- if self.google_login(user, password):
- res = {
- 'gmail_user': user,
- 'gmail_password': password
- }
- self.pool.get('res.users').write(cr, uid, uid, res, context=context)
- else:
- raise osv.except_osv(_('Error!'), _("Authentication failed. Check the user and password."))
-
- return self._get_next_action(cr, uid, context=context)
-
- def _get_next_action(self, cr, uid, context=None):
- return {'type': 'ir.actions.act_window_close'}
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/google_base_account/wizard/google_login_view.xml b/addons/google_base_account/wizard/google_login_view.xml
deleted file mode 100644
index ed345ab5a0f..00000000000
--- a/addons/google_base_account/wizard/google_login_view.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0"?>
-<openerp>
- <data>
- <record model="ir.ui.view" id="view_google_login_form">
- <field name="name">google.login.form</field>
- <field name="model">google.login</field>
- <field name="arch" type="xml">
- <form string="Google login" version="7.0">
- <group>
- <field name="user" placeholder="e.g. user@gmail.com"/>
- <field name="password" password="True"/>
- </group>
- <footer>
- <button name="login" string="_Login" type="object" class="oe_highlight"/>
- or
- <button string="Cancel" class="oe_link" special="cancel" />
- </footer>
- </form>
- </field>
- </record>
-
- <!--
- Login Action
- -->
- <record model="ir.actions.act_window" id="act_google_login_form">
- <field name="name">Google Login</field>
- <field name="type">ir.actions.act_window</field>
- <field name="res_model">google.login</field>
- <field name="view_type">form</field>
- <field name="view_mode">form</field>
- <field name="target">new</field>
- <field name="view_id" ref="view_google_login_form" />
- </record>
- </data>
-</openerp>