def get_user_details(self, response): """Return user details from an OpenID request""" take_user_data.send(sender=self.__class__, **{'response': response}) values = {'username': '', 'email': '', 'fullname': '', 'first_name': '', 'last_name': ''} # update values using SimpleRegistration or AttributeExchange # values values.update(self.values_from_response(response, SREG_ATTR, OLD_AX_ATTRS + AX_SCHEMA_ATTRS)) fullname = values.get('fullname') or '' first_name = values.get('first_name') or '' last_name = values.get('last_name') or '' if not fullname and first_name and last_name: fullname = first_name + ' ' + last_name elif fullname: try: # Try to split name for django user storage first_name, last_name = fullname.rsplit(' ', 1) except ValueError: last_name = fullname values.update({ 'fullname': fullname, 'first_name': first_name, 'last_name': last_name, 'username': values.get('username') or (first_name.title() + last_name.title()) }) return values
def extra_data(cls, user, uid, response, details=None): """Return access_token and extra defined names to store in extra_data field""" take_user_data.send(sender=cls, **{'response': response}) data = {'access_token': response.get('access_token', '')} name = cls.name.replace('-', '_').upper() names = (cls.EXTRA_DATA or []) + setting(name + '_EXTRA_DATA', []) for entry in names: if len(entry) == 2: (name, alias), discard = entry, False elif len(entry) == 3: name, alias, discard = entry elif len(entry) == 1: name = alias = entry discard = False else: # ??? continue value = response.get(name) if discard and not value: continue data[alias] = value return data