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.addons.auth_signup.res_users import SignupError
27 from openerp.osv import osv, fields
29 _logger = logging.getLogger(__name__)
31 class res_users(osv.Model):
32 _inherit = 'res.users'
34 def _auth_oauth_signin(self, cr, uid, provider, validation, params, context=None):
35 # overridden to use signup method if regular oauth signin fails
37 login = super(res_users, self)._auth_oauth_signin(cr, uid, provider, validation, params, context=context)
39 except openerp.exceptions.AccessDenied, access_denied_exception:
40 if context and context.get('no_user_creation'):
42 state = simplejson.loads(params['state'])
43 token = state.get('t')
44 oauth_uid = validation['user_id']
45 email = validation.get('email', 'provider_%s_user_%s' % (provider, oauth_uid))
46 name = validation.get('name', email)
51 'oauth_provider_id': provider,
52 'oauth_uid': oauth_uid,
53 'oauth_access_token': params['access_token'],
57 _, login, _ = self.signup(cr, uid, values, token, context=context)
59 raise access_denied_exception