Projet

Général

Profil

0002-LDAPBackend-reactive-user-on-login-synchronization-i.patch

Benjamin Renard, 09 avril 2021 17:08

Télécharger (2,38 ko)

Voir les différences:

Subject: [PATCH 2/2] LDAPBackend: reactive user on login/synchronization if
 inactive

 src/authentic2/backends/ldap_backend.py | 10 ++++++++--
 src/authentic2/custom_user/models.py    |  5 +++++
 2 files changed, 13 insertions(+), 2 deletions(-)
src/authentic2/backends/ldap_backend.py
821 821
                    log.error('user bind failed: authz_id not found %r', ', '.join(authz_ids))
822 822
                    if block['replicas']:
823 823
                        break
824
                return self._return_user(authz_id, password, conn, block)
824
                user = self._return_user(authz_id, password, conn, block)
825
                if user and not user.is_active:
826
                    user.mark_as_active()
827
                return user
825 828
            except ldap.CONNECT_ERROR:
826 829
                log.error(
827 830
                    'connection to %r failed, did you forget to declare the TLS certificate '
......
1475 1478
            )
1476 1479
            backend = cls()
1477 1480
            for dn, attrs in results:
1478
                yield backend._return_user(dn, None, conn, block, attrs)
1481
                user = backend._return_user(dn, None, conn, block, attrs)
1482
                if user and not user.is_active:
1483
                    user.mark_as_active()
1484
                yield user
1479 1485

  
1480 1486
    @classmethod
1481 1487
    def deactivate_orphaned_users(cls):
src/authentic2/custom_user/models.py
360 360
            del self._a2_attributes_cache
361 361
        return super(User, self).refresh_from_db(*args, **kwargs)
362 362

  
363
    def mark_as_active(self):
364
        self.is_active = True
365
        self.deactivation = None
366
        self.save(update_fields=['is_active', 'deactivation'])
367

  
363 368
    def mark_as_inactive(self, timestamp=None):
364 369
        self.is_active = False
365 370
        self.deactivation = timestamp or timezone.now()
366
-