Commit bb3591cc authored by Alexandre's avatar Alexandre

feature: fancy error message on email unicity error #82

parent f3bf735b
......@@ -112,10 +112,6 @@ class Info(Model):
def __str__(self):
return self.newspaper +" "+ self.headline[:20]
@receiver(pre_save, sender=User)
def copy_email_to_username(sender, instance, *args, **kwargs):
instance.username =
@receiver(post_save, sender=Action)
def save_autojoin_action(sender, instance, created, **kwargs):
if created:
from registration.forms import RegistrationForm
from django.forms import CharField
from django.forms import CharField, ValidationError
from django.contrib.auth.models import User
from data_manager.models import UserProfile
......@@ -12,6 +12,12 @@ class EmailRegistrationForm(RegistrationForm):
self.fields['last_name'].required = False
self.fields['postcode'].required = False
def clean_email(self):
if User.objects.filter(username=self.cleaned_data['email']).exists():
raise ValidationError("Un utilisateur avec cette adresse email existe déjà.")
self.instance.username = self.cleaned_data['email']
return self.cleaned_data['email']
def save(self):
user = super().save()
self.instance.userprofile = UserProfile(postcode=self.cleaned_data['postcode'], user=user)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment