1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-13 08:06:54 +00:00
plateforme-corres2math/apps/registration/signals.py
Yohann D'ANELLO a68a7b681d Try to add CI
2020-09-24 11:44:43 +02:00

24 lines
718 B
Python

from django.contrib.auth.models import User
from .models import AdminRegistration, Registration
def set_username(instance, **_):
instance.username = instance.email
def send_email_link(instance, **_):
if instance.pk:
old_instance = User.objects.get(pk=instance.pk)
if old_instance.email != instance.email:
registration = Registration.objects.get(user=instance)
registration.email_confirmed = False
registration.save()
registration.user = instance
registration.send_email_validation_link()
def create_admin_registration(instance, **_):
if instance.is_superuser:
AdminRegistration.objects.get_or_create(user=instance)