authomatic/providers/__init__.py
def _update_or_create_user(self, data, credentials=None, content=None):
        """
        Updates or creates :attr:`.user`.

        :returns:
            :class:`.User`

        """

        if not self.user:
            self.user = authomatic.core.User(self, credentials=credentials)

        self.user.content = content
        self.user.data = data

        # Update.
        for key in self.user.__dict__:
            # Exclude data.
            if key not in ('data', 'content'):
                # Extract every data item whose key matches the user
                # property name, but only if it has a value.
                value = data.get(key)
                if value:
                    setattr(self.user, key, value)

        # Handle different structure of data by different providers.
        self.user = self._x_user_parser(self.user, data)

        if self.user.id:
            self.user.id = str(self.user.id)

        # TODO: Move to User
        # If there is no user.name,
        if not self.user.name:
            if self.user.first_name and self.user.last_name:
                # Create it from first name and last name if available.
                self.user.name = ' '.join((self.user.first_name,
                                           self.user.last_name))
            else:
                # Or use one of these.
                self.user.name = (self.user.username or self.user.nickname or
                                  self.user.first_name or self.user.last_name)

        if not self.user.location:
            if self.user.city and self.user.country:
                self.user.location = '{0}, {1}'.format(self.user.city,
                                                       self.user.country)
            else:
                self.user.location = self.user.city or self.user.country

        return self.user
def _update_or_create_user(self, data, credentials=None, content=None):
        """
        Updates or creates :attr:`.user`.

        :returns:
            :class:`.User`

        """

        if not self.user:
            self.user = authomatic.core.User(self, credentials=credentials)

        self.user.content = content
        self.user.data = data

        # Update.
        for key in self.user.__dict__:
            # Exclude data.
            if key not in ('data', 'content'):
                # Extract every data item whose key matches the user
                # property name, but only if it has a value.
                value = data.get(key)
                if value:
                    setattr(self.user, key, value)

        # Handle different structure of data by different providers.
        self.user = self._x_user_parser(self.user, data)

        if self.user.id:
            self.user.id = str(self.user.id)

        # TODO: Move to User
        # If there is no user.name,
        if not self.user.name:
            if self.user.first_name and self.user.last_name:
                # Create it from first name and last name if available.
                self.user.name = ' '.join((self.user.first_name,
                                           self.user.last_name))
            else:
                # Or use one of these.
                self.user.name = (self.user.username or self.user.nickname or
                                  self.user.first_name or self.user.last_name)

        if not self.user.location:
            if self.user.city and self.user.country:
                self.user.location = '{0}, {1}'.format(self.user.city,
                                                       self.user.country)
            else:
                self.user.location = self.user.city or self.user.country

        return self.user
Updates or creates :attr:`.user`.

        :returns:
            :class:`.User`