[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
This commit is contained in:
Sandy Carter 2014-09-11 12:34:54 -04:00 committed by Denis Ledoux
parent 23cb6ef7df
commit 1d0187223b
1 changed files with 15 additions and 12 deletions

View File

@ -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: