1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
22 from osv import fields,osv
23 from tools.translate import _
25 import gdata.contacts.service
26 import gdata.contacts.client
27 import gdata.calendar.service
29 raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
31 class google_login(osv.osv_memory):
32 _description ='Google Contact'
33 _name = 'google.login'
35 'user': fields.char('Google Username', size=64, required=True),
36 'password': fields.char('Google Password', size=64),
39 def google_login(self, user, password, type='', context=None):
41 gd_client = gdata.contacts.client.ContactsClient(source='OpenERP')
42 if type == 'contact' :
43 gd_client = gdata.contacts.service.ContactsService()
44 if type == 'calendar':
45 gd_client = gdata.calendar.service.CalendarService()
47 gd_client = gdata.contacts.service.ContactsService()
49 gd_client.ClientLogin(user, password,gd_client.source)
55 def default_get(self, cr, uid, fields, context=None):
56 res = super(google_login, self).default_get(cr, uid, fields, context=context)
57 user_obj = self.pool.get('res.users').browse(cr, uid, uid)
59 res.update({'user': user_obj.gmail_user})
60 if 'password' in fields:
61 res.update({'password': user_obj.gmail_password})
64 def login(self, cr, uid, ids, context=None):
65 data = self.read(cr, uid, ids)[0]
67 password = data['password']
68 if self.google_login(user, password):
71 'gmail_password': password
73 self.pool.get('res.users').write(cr, uid, uid, res, context=context)
75 raise osv.except_osv(_('Error'), _("Authentication fail check the user and password !"))
77 return self._get_next_action(cr, uid, context=context)
79 def _get_next_action(self, cr, uid, context=None):
80 return {'type': 'ir.actions.act_window_close'}
84 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: