8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +00:00

fix mail problems: check pseudo taken and lower)

This commit is contained in:
Charlie Jacomme 2018-08-10 19:27:10 +02:00 committed by Hugo LEVY-FALK
parent 84764ce51b
commit e70b063a3d

View file

@ -103,6 +103,13 @@ def linux_user_validator(login):
params={'label': login},
)
def pseudo_taken(login):
""" Retourne une erreur de validation si le login ne respecte
pas les contraintes unix (maj, min, chiffres ou tiret)"""
if (EMailAddress.objects
.filter(local_part=login.lower())):
raise forms.ValidationError('Pseudo is already taken')
def get_fresh_user_uid():
""" Renvoie le plus petit uid non pris. Fonction très paresseuse """
@ -193,7 +200,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
max_length=32,
unique=True,
help_text="Doit contenir uniquement des lettres, chiffres, ou tirets",
validators=[linux_user_validator]
validators=[linux_user_validator, pseudo_taken]
)
email = models.EmailField()
local_email_redirect = models.BooleanField(
@ -966,8 +973,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
"""Check if this pseudo is already used by any mailalias.
Better than raising an error in post-save and catching it"""
if (EMailAddress.objects
.filter(local_part=self.pseudo)
.exclude(user=self)):
.filter(local_part=self.pseudo.lower()).exclude(user=self)
):
raise ValidationError("This pseudo is already in use.")
def __str__(self):
@ -1106,7 +1113,7 @@ def user_post_save(**kwargs):
Synchronise le ldap"""
is_created = kwargs['created']
user = kwargs['instance']
EMailAddress.objects.get_or_create(local_part=user.pseudo, user=user)
EMailAddress.objects.get_or_create(local_part=user.pseudo.lower(), user=user)
if is_created:
user.notif_inscription()
user.state_sync()
@ -1803,6 +1810,7 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
"local email account")
def clean(self, *args, **kwargs):
self.local_part = self.local_part.lower()
if "@" in self.local_part:
raise ValidationError("The local part cannot contain a @")
super(EMailAddress, self).clean(*args, **kwargs)