8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 20:03:11 +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}, 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(): def get_fresh_user_uid():
""" Renvoie le plus petit uid non pris. Fonction très paresseuse """ """ Renvoie le plus petit uid non pris. Fonction très paresseuse """
@ -193,7 +200,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
max_length=32, max_length=32,
unique=True, unique=True,
help_text="Doit contenir uniquement des lettres, chiffres, ou tirets", help_text="Doit contenir uniquement des lettres, chiffres, ou tirets",
validators=[linux_user_validator] validators=[linux_user_validator, pseudo_taken]
) )
email = models.EmailField() email = models.EmailField()
local_email_redirect = models.BooleanField( local_email_redirect = models.BooleanField(
@ -966,8 +973,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
"""Check if this pseudo is already used by any mailalias. """Check if this pseudo is already used by any mailalias.
Better than raising an error in post-save and catching it""" Better than raising an error in post-save and catching it"""
if (EMailAddress.objects if (EMailAddress.objects
.filter(local_part=self.pseudo) .filter(local_part=self.pseudo.lower()).exclude(user=self)
.exclude(user=self)): ):
raise ValidationError("This pseudo is already in use.") raise ValidationError("This pseudo is already in use.")
def __str__(self): def __str__(self):
@ -1106,7 +1113,7 @@ def user_post_save(**kwargs):
Synchronise le ldap""" Synchronise le ldap"""
is_created = kwargs['created'] is_created = kwargs['created']
user = kwargs['instance'] 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: if is_created:
user.notif_inscription() user.notif_inscription()
user.state_sync() user.state_sync()
@ -1803,6 +1810,7 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
"local email account") "local email account")
def clean(self, *args, **kwargs): def clean(self, *args, **kwargs):
self.local_part = self.local_part.lower()
if "@" in self.local_part: if "@" in self.local_part:
raise ValidationError("The local part cannot contain a @") raise ValidationError("The local part cannot contain a @")
super(EMailAddress, self).clean(*args, **kwargs) super(EMailAddress, self).clean(*args, **kwargs)