[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:
parent
23cb6ef7df
commit
1d0187223b
|
@ -31,6 +31,20 @@ _logger = logging.getLogger(__name__)
|
||||||
class res_users(osv.Model):
|
class res_users(osv.Model):
|
||||||
_inherit = 'res.users'
|
_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):
|
def _auth_oauth_signin(self, cr, uid, provider, validation, params, context=None):
|
||||||
# overridden to use signup method if regular oauth signin fails
|
# overridden to use signup method if regular oauth signin fails
|
||||||
try:
|
try:
|
||||||
|
@ -41,18 +55,7 @@ class res_users(osv.Model):
|
||||||
return None
|
return None
|
||||||
state = simplejson.loads(params['state'])
|
state = simplejson.loads(params['state'])
|
||||||
token = state.get('t')
|
token = state.get('t')
|
||||||
oauth_uid = validation['user_id']
|
values = self._generate_signup_values(cr, uid, provider, validation, params, context=context)
|
||||||
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,
|
|
||||||
}
|
|
||||||
try:
|
try:
|
||||||
_, login, _ = self.signup(cr, uid, values, token, context=context)
|
_, login, _ = self.signup(cr, uid, values, token, context=context)
|
||||||
except SignupError:
|
except SignupError:
|
||||||
|
|
Loading…
Reference in New Issue