initial
This commit is contained in:
23
frontend/signals.py
Normal file
23
frontend/signals.py
Normal file
@@ -0,0 +1,23 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user