mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:22:26 +00:00
fix mail problems: check pseudo taken and lower)
This commit is contained in:
parent
6157b42ee8
commit
e1e2ccab9a
1 changed files with 12 additions and 3 deletions
|
@ -104,6 +104,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 """
|
||||||
|
@ -195,7 +202,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(
|
||||||
blank=True,
|
blank=True,
|
||||||
|
@ -1132,8 +1139,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(
|
EMailAddress.objects.get_or_create(local_part=user.pseudo.lower(), user=user)
|
||||||
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()
|
||||||
|
@ -1740,6 +1746,9 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.local_part) + OptionalUser.get_cached_value('local_email_domain')
|
return str(self.local_part) + OptionalUser.get_cached_value('local_email_domain')
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
self.local_part = self.local_part.lower()
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def complete_email_address(self):
|
def complete_email_address(self):
|
||||||
return str(self.local_part) + OptionalUser.get_cached_value('local_email_domain')
|
return str(self.local_part) + OptionalUser.get_cached_value('local_email_domain')
|
||||||
|
|
Loading…
Reference in a new issue