8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 14:42:25 +00:00

Ajoute la possibilité d'utiliser uniquement le compte mail local.

This commit is contained in:
Hugo LEVY-FALK 2018-08-14 13:09:13 +02:00
parent 680b8a7ec7
commit 49585cade1
2 changed files with 31 additions and 12 deletions

View file

@ -15,7 +15,7 @@ class Migration(migrations.Migration):
migrations.AlterField( migrations.AlterField(
model_name='user', model_name='user',
name='email', name='email',
field=models.EmailField(blank=True, help_text='External email address allowing us to contact you.', max_length=254), field=models.EmailField(blank=True, null=True, help_text='External email address allowing us to contact you.', max_length=254),
), ),
migrations.AlterField( migrations.AlterField(
model_name='user', model_name='user',

View file

@ -104,6 +104,7 @@ def linux_user_validator(login):
params={'label': login}, params={'label': login},
) )
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 """
uids = list(range( uids = list(range(
@ -131,6 +132,7 @@ def get_fresh_gid():
class UserManager(BaseUserManager): class UserManager(BaseUserManager):
"""User manager basique de django""" """User manager basique de django"""
def _create_user( def _create_user(
self, self,
pseudo, pseudo,
@ -197,6 +199,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
) )
email = models.EmailField( email = models.EmailField(
blank=True, blank=True,
null=True,
help_text="External email address allowing us to contact you." help_text="External email address allowing us to contact you."
) )
local_email_redirect = models.BooleanField( local_email_redirect = models.BooleanField(
@ -563,13 +566,15 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
user_ldap.gid = LDAP['user_gid'] user_ldap.gid = LDAP['user_gid']
if '{SSHA}' in self.password or '{SMD5}' in self.password: if '{SSHA}' in self.password or '{SMD5}' in self.password:
# We remove the extra $ added at import from ldap # We remove the extra $ added at import from ldap
user_ldap.user_password = self.password[:6] + self.password[7:] user_ldap.user_password = self.password[:6] + \
self.password[7:]
elif '{crypt}' in self.password: elif '{crypt}' in self.password:
# depending on the length, we need to remove or not a $ # depending on the length, we need to remove or not a $
if len(self.password)==41: if len(self.password) == 41:
user_ldap.user_password = self.password user_ldap.user_password = self.password
else: else:
user_ldap.user_password = self.password[:7] + self.password[8:] user_ldap.user_password = self.password[:7] + \
self.password[8:]
user_ldap.sambat_nt_password = self.pwd_ntlm.upper() user_ldap.sambat_nt_password = self.pwd_ntlm.upper()
if self.get_shell: if self.get_shell:
@ -961,7 +966,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
'force': self.can_change_force, 'force': self.can_change_force,
'selfpasswd': self.check_selfpasswd, 'selfpasswd': self.check_selfpasswd,
'local_email_redirect': self.can_change_local_email_redirect, 'local_email_redirect': self.can_change_local_email_redirect,
'local_email_enabled' : self.can_change_local_email_enabled, 'local_email_enabled': self.can_change_local_email_enabled,
} }
self.__original_state = self.state self.__original_state = self.state
@ -972,6 +977,19 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
.filter(local_part=self.pseudo.lower()).exclude(user_id=self.id) .filter(local_part=self.pseudo.lower()).exclude(user_id=self.id)
): ):
raise ValidationError("This pseudo is already in use.") raise ValidationError("This pseudo is already in use.")
if not self.local_email_enabled and not self.email:
raise ValidationError(
{'email': (
'There is neither a local email address nor an external'
' email address for this user.'
), }
)
if self.local_email_redirect and not self.email:
raise ValidationError(
{'local_email_redirect': (
'You cannot redirect your local email if no external email '
'has been set.'), }
)
def __str__(self): def __str__(self):
return self.pseudo return self.pseudo
@ -1109,7 +1127,8 @@ 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.lower(), 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()
@ -1132,6 +1151,7 @@ def user_group_relation_changed(**kwargs):
mac_refresh=False, mac_refresh=False,
group_refresh=True) group_refresh=True)
@receiver(post_delete, sender=Adherent) @receiver(post_delete, sender=Adherent)
@receiver(post_delete, sender=Club) @receiver(post_delete, sender=Club)
@receiver(post_delete, sender=User) @receiver(post_delete, sender=User)
@ -1810,4 +1830,3 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
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)