2020-09-22 17:37:37 +00:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
2020-09-24 09:44:43 +00:00
|
|
|
from .models import AdminRegistration, Registration
|
2020-09-22 10:27:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def set_username(instance, **_):
|
|
|
|
instance.username = instance.email
|
|
|
|
|
|
|
|
|
2020-09-22 17:37:37 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2020-09-22 10:27:03 +00:00
|
|
|
def create_admin_registration(instance, **_):
|
|
|
|
if instance.is_superuser:
|
|
|
|
AdminRegistration.objects.get_or_create(user=instance)
|