Example #1
0
 def set_password(self, password):
     super(Person, self).set_password(password)
     if self.legacy_ldap_password is not None:
         self.legacy_ldap_password = None
     super(Person, self).save()
     from karaage.datastores import set_person_password
     set_person_password(self, password)
     for ua in self.account_set.filter(date_deleted__isnull=True):
         ua.set_password(password)
     log(None, self, 2, 'Changed Password')
Example #2
0
    def save(self, *args, **kwargs):
        # save the object
        super(Person, self).save(*args, **kwargs)

        # update the datastore
        from karaage.datastores import save_person

        save_person(self)

        # update account datastores
        from karaage.datastores import save_account

        for ua in self.account_set.filter(date_deleted__isnull=True):
            save_account(ua)

        # has username changed?
        old_username = self._username
        new_username = self.username
        if old_username != new_username:
            from karaage.datastores import set_person_username

            set_person_username(self, old_username, new_username)

        # has locked status changed?
        old_login_enabled = self._login_enabled
        new_login_enabled = self.login_enabled
        if old_login_enabled != new_login_enabled:
            if new_login_enabled:
                for ua in self.account_set.filter(date_deleted__isnull=True):
                    ua.unlock()
                log(None, self, 2, "Unlocked person")
            else:
                for ua in self.account_set.filter(date_deleted__isnull=True):
                    ua.lock()
                log(None, self, 2, "Locked person")

        # has the institute changed?
        old_institute = self._institute
        new_institute = self.institute
        if old_institute != new_institute:
            if old_institute is not None:
                from karaage.datastores import remove_person_from_institute

                remove_person_from_institute(self, old_institute)
                from karaage.datastores import remove_account_from_institute

                for account in self.account_set.filter(date_deleted__isnull=True):
                    remove_account_from_institute(account, old_institute)
            if new_institute is not None:
                from karaage.datastores import add_person_to_institute

                add_person_to_institute(self, new_institute)
                from karaage.datastores import add_account_to_institute

                for account in self.account_set.filter(date_deleted__isnull=True):
                    add_account_to_institute(account, new_institute)

        if self._password is not None:
            from karaage.datastores import set_person_password

            set_person_password(self, self._password)
            for ua in self.account_set.filter(date_deleted__isnull=True):
                ua.set_password(self._password)
                ua.save()
            log(None, self, 2, "Changed Password")
            self._password = None

        # log message
        log(None, self, 2, "Saved person")

        # save current state
        self._username = self.username
        self._login_enabled = self.login_enabled
        self._institute = self.institute