mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 20:03:11 +00:00
Ajoute la possibilité d'utiliser uniquement le compte mail local.
This commit is contained in:
parent
680b8a7ec7
commit
49585cade1
2 changed files with 31 additions and 12 deletions
|
@ -15,7 +15,7 @@ class Migration(migrations.Migration):
|
|||
migrations.AlterField(
|
||||
model_name='user',
|
||||
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(
|
||||
model_name='user',
|
||||
|
|
|
@ -104,6 +104,7 @@ def linux_user_validator(login):
|
|||
params={'label': login},
|
||||
)
|
||||
|
||||
|
||||
def get_fresh_user_uid():
|
||||
""" Renvoie le plus petit uid non pris. Fonction très paresseuse """
|
||||
uids = list(range(
|
||||
|
@ -131,6 +132,7 @@ def get_fresh_gid():
|
|||
|
||||
class UserManager(BaseUserManager):
|
||||
"""User manager basique de django"""
|
||||
|
||||
def _create_user(
|
||||
self,
|
||||
pseudo,
|
||||
|
@ -197,6 +199,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
)
|
||||
email = models.EmailField(
|
||||
blank=True,
|
||||
null=True,
|
||||
help_text="External email address allowing us to contact you."
|
||||
)
|
||||
local_email_redirect = models.BooleanField(
|
||||
|
@ -563,13 +566,15 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
user_ldap.gid = LDAP['user_gid']
|
||||
if '{SSHA}' in self.password or '{SMD5}' in self.password:
|
||||
# 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:
|
||||
# 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
|
||||
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()
|
||||
if self.get_shell:
|
||||
|
@ -961,7 +966,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
'force': self.can_change_force,
|
||||
'selfpasswd': self.check_selfpasswd,
|
||||
'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
|
||||
|
||||
|
@ -972,6 +977,19 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
.filter(local_part=self.pseudo.lower()).exclude(user_id=self.id)
|
||||
):
|
||||
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):
|
||||
return self.pseudo
|
||||
|
@ -1109,7 +1127,8 @@ def user_post_save(**kwargs):
|
|||
Synchronise le ldap"""
|
||||
is_created = kwargs['created']
|
||||
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:
|
||||
user.notif_inscription()
|
||||
user.state_sync()
|
||||
|
@ -1132,6 +1151,7 @@ def user_group_relation_changed(**kwargs):
|
|||
mac_refresh=False,
|
||||
group_refresh=True)
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Adherent)
|
||||
@receiver(post_delete, sender=Club)
|
||||
@receiver(post_delete, sender=User)
|
||||
|
@ -1810,4 +1830,3 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
|
|||
if "@" in self.local_part:
|
||||
raise ValidationError("The local part cannot contain a @")
|
||||
super(EMailAddress, self).clean(*args, **kwargs)
|
||||
|
||||
|
|
Loading…
Reference in a new issue