From 1d0187223bb4f91da97455640f7fad54d44a4023 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Thu, 11 Sep 2014 12:34:54 -0400 Subject: [PATCH] [FIX] auth_oauth_signup: Factor out user signup values There is no easy way to edit the values sent to newly generated users from oauth_signup. In some cases, the mapping from an oauth provider can be different. * ex: login is something other than email In other cases, there are additional fields in res_users added by a module * ex: firstname and last name in `partner_firstname` This factorization allows modules inheriting from `auth_oauth_signup` to alter values sent to the copy of Template User. This means smaller changes to the default behaviour and the ability to properly inherit (multiple times if needed) this module without losing needed behaviour. Closes #2355 --- addons/auth_oauth_signup/res_users.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/addons/auth_oauth_signup/res_users.py b/addons/auth_oauth_signup/res_users.py index a06968fa46f..3f011aa14db 100644 --- a/addons/auth_oauth_signup/res_users.py +++ b/addons/auth_oauth_signup/res_users.py @@ -31,6 +31,20 @@ _logger = logging.getLogger(__name__) class res_users(osv.Model): _inherit = 'res.users' + def _generate_signup_values(self, cr, uid, provider, validation, params, context=None): + oauth_uid = validation['user_id'] + email = validation.get('email', 'provider_%s_user_%s' % (provider, oauth_uid)) + name = validation.get('name', email) + return { + 'name': name, + 'login': email, + 'email': email, + 'oauth_provider_id': provider, + 'oauth_uid': oauth_uid, + 'oauth_access_token': params['access_token'], + 'active': True, + } + def _auth_oauth_signin(self, cr, uid, provider, validation, params, context=None): # overridden to use signup method if regular oauth signin fails try: @@ -41,18 +55,7 @@ class res_users(osv.Model): return None state = simplejson.loads(params['state']) token = state.get('t') - oauth_uid = validation['user_id'] - email = validation.get('email', 'provider_%s_user_%s' % (provider, oauth_uid)) - name = validation.get('name', email) - values = { - 'name': name, - 'login': email, - 'email': email, - 'oauth_provider_id': provider, - 'oauth_uid': oauth_uid, - 'oauth_access_token': params['access_token'], - 'active': True, - } + values = self._generate_signup_values(cr, uid, provider, validation, params, context=context) try: _, login, _ = self.signup(cr, uid, values, token, context=context) except SignupError: