Files
Holger Sielaff 90c0ff61ed initial
2025-08-27 09:55:55 +02:00

24 lines
822 B
Python

import logging
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User
from .models import UserProfile
from lib.ldap import Ldap
from lib.decorators import skip_signal
@receiver(post_save, sender=User)
@skip_signal()
def post_save_user_profile(sender, instance: User, created, **kwargs):
with Ldap() as ldap:
try:
ldap.set_user_groups(instance, save_instance=True)
except Exception as e:
logging.exception(e)
return
try:
if created or not UserProfile.objects.filter(ldap_uid=instance.username).exists():
UserProfile.objects.create(user=instance,ldap_uid=instance.username)
except Exception as e:
logging.exception("WTF???", str(e))