How to use the djangosaml2.signals.pre_user_save function in djangosaml2

To help you get started, we’ve selected a few djangosaml2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudera / hue / desktop / core / ext-py / djangosaml2-0.16.4 / djangosaml2 / backends.py View on Github external
user_attr = getattr(user, attr)
                    if callable(user_attr):
                        modified = user_attr(attr_value_list)
                    else:
                        modified = self._set_attribute(user, attr, attr_value_list[0])

                    user_modified = user_modified or modified

                elif profile is not None and hasattr(profile, attr):
                    modified = self._set_attribute(profile, attr, attr_value_list[0])
                    profile_modified = profile_modified or modified

        logger.debug('Sending the pre_save signal')
        signal_modified = any(
            [response for receiver, response
             in pre_user_save.send_robust(sender=user.__class__,
                                          instance=user,
                                          attributes=attributes,
                                          user_modified=user_modified)]
            )

        if user_modified or signal_modified or force_save:
            user.save()

        if (profile is not None
            and (profile_modified or signal_modified or force_save)):
            profile.save()

        return user
github knaperek / djangosaml2 / djangosaml2 / backends.py View on Github external
def send_user_update_signal(self, user: settings.AUTH_USER_MODEL, attributes: dict, user_modified: bool) -> bool:
        """ Send out a pre-save signal after the user has been updated with the SAML attributes.
            This does not have to be overwritten, but depending on your custom implementation of get_or_create_user,
            you might want to not send out this signal. In that case, just override this method to return False.
        """
        logger.debug('Sending the pre_save signal')
        signal_modified = any(
            [response for receiver, response
             in pre_user_save.send_robust(sender=user.__class__,
                                          instance=user,
                                          attributes=attributes,
                                          user_modified=user_modified)]
            )
        return signal_modified
github OpenMOOC / askbot-openmooc / askbotopenmooc / app / models.py View on Github external
# if user is a new user
    if user.username is None:
        change_username(user, candidate)
        return True
    else:
        user_old = User.objects.get(id=user.id)
        # If user has changed his first_name or last_name
        if ((user_old.first_name != user.first_name) or
            (user_old.last_name != user.last_name)):

            change_username(user, candidate)
            return True


pre_user_save.connect(askbot_pre_user_save)
github grahamgilbert / crypt-server-saml / signals.py View on Github external
@receiver(pre_user_save)
def update_group_membership(
        sender, instance, attributes: dict, user_modified: bool, **kwargs) -> bool:
    """Update user's group membership based on passed SAML groups

    Args:
        sender: The class of the user that just logged in.
        instance: User instance
        attributes: SAML attributes dict.
        user_modified: Bool whether the user has been modified
        kwargs:
            signal: The signal instance

    Returns:
        Whether or not the user has been modified. This allows the user
        instance to be saved once at the conclusion of the auth process
        to keep the writes to a minimum.