1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2010-2012 OpenERP SA (<http://openerp.com>).
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 ##############################################################################
26 from openerp.osv import osv, fields
28 _logger = logging.getLogger(__name__)
30 class res_users(osv.Model):
31 _inherit = 'res.users'
33 def _auth_oauth_signin(self, cr, uid, provider, validation, params, context=None):
34 # overridden to use signup method if regular oauth signin fails
36 login = super(res_users, self)._auth_oauth_signin(cr, uid, provider, validation, params, context=context)
38 except openerp.exceptions.AccessDenied:
39 state = simplejson.loads(params['state'])
40 token = state.get('t')
41 oauth_uid = validation['user_id']
42 email = validation.get('email', 'provider_%d_user_%d' % (provider, oauth_uid))
43 name = validation.get('name', email)
48 'oauth_provider_id': provider,
49 'oauth_uid': oauth_uid,
50 'oauth_access_token': params['access_token'],
53 _, login, _ = self.signup(cr, uid, values, token, context=context)