diff --git a/home/signals.py b/home/signals.py new file mode 100644 index 0000000..73b9847 --- /dev/null +++ b/home/signals.py @@ -0,0 +1,39 @@ +import os + +import requests +from django.conf import settings +from django.contrib.auth.models import User +from django.db.models.signals import post_save +from django.dispatch import receiver + + +@receiver(post_save, sender=User) +def notify_external_service_on_signup(sender, instance, created, **kwargs): + pass + # if created and not instance.is_staff: + # payload = { + # "user_id": instance.id, + # "username": f"KURSY-{instance.id}", + # "email": instance.email, + # "full_name": f"{instance.first_name} {instance.last_name}".strip(), + # # "must_change_password": True, + # # "password": instance.password, + # "visibility": "private", + # } + # api_url = getattr(settings, "GITEA_URL", None) + # if api_url: + # url = f"{api_url}/admin/users" + # try: + # response = requests.post( + # url, + # json=payload, + # timeout=5, + # headers={"Authorization": f"token {os.getenv('GITEA_API_TOKEN')}"}, + # ) + # response.raise_for_status() + # print(f"Successfully created Gitea account for {instance.email}") + # except Exception as e: + # print( + # f"Failed to create Gitea account for user {instance.email}: {e}\n{response.text}" + # ) + # raise e