|
|
|
|
@ -23,6 +23,22 @@ class CustomUserCreationForm(UserCreationForm): |
|
|
|
|
raise forms.ValidationError('Le numéro de licence est invalide, la lettre ne correspond pas.') |
|
|
|
|
return licence_id |
|
|
|
|
|
|
|
|
|
def clean_email(self): |
|
|
|
|
email = self.cleaned_data.get('email') |
|
|
|
|
if email: |
|
|
|
|
email = email.lower() |
|
|
|
|
if CustomUser.objects.filter(email__iexact=email).exclude(pk=self.instance.pk).exists(): |
|
|
|
|
raise forms.ValidationError("Cet email est déjà utilisé. Veuillez en choisir un autre :)") |
|
|
|
|
return email |
|
|
|
|
|
|
|
|
|
def clean_username(self): |
|
|
|
|
username = self.cleaned_data.get('username') |
|
|
|
|
if username: |
|
|
|
|
username = username.lower() |
|
|
|
|
if CustomUser.objects.filter(username__iexact=username).exclude(pk=self.instance.pk).exists() | CustomUser.objects.filter(email__iexact=username).exclude(pk=self.instance.pk).exists(): |
|
|
|
|
raise forms.ValidationError("Cet identifiant est déjà utilisé. Veuillez en choisir un autre :)") |
|
|
|
|
return username |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
model = CustomUser |
|
|
|
|
error_messages = { |
|
|
|
|
@ -91,16 +107,32 @@ class SimpleCustomUserCreationForm(UserCreationForm): |
|
|
|
|
'password2': 'Confirmer le mot de passe', |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
def clean_email(self): |
|
|
|
|
email = self.cleaned_data.get('email') |
|
|
|
|
if email: |
|
|
|
|
email = email.lower() |
|
|
|
|
if CustomUser.objects.filter(email__iexact=email).exclude(pk=self.instance.pk).exists(): |
|
|
|
|
raise forms.ValidationError("Cet email est déjà utilisé. Veuillez en choisir un autre :)") |
|
|
|
|
return email |
|
|
|
|
|
|
|
|
|
def clean_username(self): |
|
|
|
|
username = self.cleaned_data.get('username') |
|
|
|
|
if username: |
|
|
|
|
username = username.lower() |
|
|
|
|
if CustomUser.objects.filter(username__iexact=username).exists() | CustomUser.objects.filter(email__iexact=username).exists(): |
|
|
|
|
if CustomUser.objects.filter(username__iexact=username).exclude(pk=self.instance.pk).exists() | CustomUser.objects.filter(email__iexact=username).exclude(pk=self.instance.pk).exists(): |
|
|
|
|
raise forms.ValidationError("Cet identifiant est déjà utilisé. Veuillez en choisir un autre :)") |
|
|
|
|
return username |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomUserChangeForm(UserChangeForm): |
|
|
|
|
def clean_username(self): |
|
|
|
|
username = self.cleaned_data.get('username') |
|
|
|
|
if username: |
|
|
|
|
username = username.lower() |
|
|
|
|
if CustomUser.objects.filter(username__iexact=username).exclude(pk=self.instance.pk).exists() | CustomUser.objects.filter(email__iexact=username).exclude(pk=self.instance.pk).exists(): |
|
|
|
|
raise forms.ValidationError("Cet identifiant est déjà utilisé. Veuillez en choisir un autre :)") |
|
|
|
|
return username |
|
|
|
|
|
|
|
|
|
def clean_licence_id(self): |
|
|
|
|
licence_id = self.cleaned_data.get('licence_id') |
|
|
|
|
if licence_id: |
|
|
|
|
@ -226,6 +258,22 @@ class ProfileUpdateForm(forms.ModelForm): |
|
|
|
|
# Remove autofocus from the 'username' field |
|
|
|
|
self.fields['username'].widget.attrs.pop("autofocus", None) |
|
|
|
|
|
|
|
|
|
def clean_email(self): |
|
|
|
|
email = self.cleaned_data.get('email') |
|
|
|
|
if email: |
|
|
|
|
email = email.lower() |
|
|
|
|
if CustomUser.objects.filter(email__iexact=email).exclude(pk=self.instance.pk).exists(): |
|
|
|
|
raise forms.ValidationError("Cet email est déjà utilisé. Veuillez en choisir un autre :)") |
|
|
|
|
return email |
|
|
|
|
|
|
|
|
|
def clean_username(self): |
|
|
|
|
username = self.cleaned_data.get('username') |
|
|
|
|
if username: |
|
|
|
|
username = username.lower() |
|
|
|
|
if CustomUser.objects.filter(username__iexact=username).exclude(pk=self.instance.pk).exists() | CustomUser.objects.filter(email__iexact=username).exclude(pk=self.instance.pk).exists(): |
|
|
|
|
raise forms.ValidationError("Cet identifiant est déjà utilisé. Veuillez en choisir un autre :)") |
|
|
|
|
return username |
|
|
|
|
|
|
|
|
|
def clean_licence_id(self): |
|
|
|
|
licence_id = self.cleaned_data.get('licence_id') |
|
|
|
|
if licence_id: |
|
|
|
|
|