3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-22 11:23:11 +00:00

Unique email

This commit is contained in:
Yoann Pétri 2019-09-23 17:22:21 +02:00
parent 8fe2008c7c
commit b5a1df1271
5 changed files with 6 additions and 23 deletions

View file

@ -21,6 +21,12 @@ class CreateUserForm(forms.ModelForm):
school = forms.ModelChoiceField(queryset=School.objects.all(), label="École") school = forms.ModelChoiceField(queryset=School.objects.all(), label="École")
def clean(self):
cleaned_data = super().clean()
email = cleaned_data.get("email")
if User.objects.filter(email=email).count() > 0:
raise forms.ValidationError("L'email est déjà utilisé")
class CreateGroupForm(forms.ModelForm): class CreateGroupForm(forms.ModelForm):
""" """
Form to create a new group (:class:`django.contrib.auth.models.Group`). Form to create a new group (:class:`django.contrib.auth.models.Group`).

View file

@ -8,8 +8,6 @@ from preferences.models import PaymentMethod, Cotisation
from gestion.models import ConsumptionHistory from gestion.models import ConsumptionHistory
User._meta.get_field('email')._unique = True
class School(models.Model): class School(models.Model):
""" """
Stores school. Stores school.

View file

@ -58,9 +58,6 @@
{% if self %} {% if self %}
<span class="tabulation"><a href="{% url 'users:editPassword' user.pk %}"><i class="fa fa-user-lock"></i> Changer mon mot de passe</a></span> <span class="tabulation"><a href="{% url 'users:editPassword' user.pk %}"><i class="fa fa-user-lock"></i> Changer mon mot de passe</a></span>
{% endif %} {% endif %}
{% if perms.users.can_reset_password %}
<span class="tabulation"><a href="{% url 'users:resetPassword' user.pk %}"><i class="fa fa-lock-open"></i> Réinitialiser le mot de passe</a></span>
{% endif %}
{% if perms.users.can_change_user_perm %} {% if perms.users.can_change_user_perm %}
<span class="tabulation"><a href="{% url 'users:editGroups' user.pk %}"><i class="fa fa-layer-group"></i> Changer les groupes</a></span> <span class="tabulation"><a href="{% url 'users:editGroups' user.pk %}"><i class="fa fa-layer-group"></i> Changer les groupes</a></span>
{% endif %} {% endif %}

View file

@ -14,7 +14,6 @@ urlpatterns = [
path('editGroups/<int:pk>', views.editGroups, name="editGroups"), path('editGroups/<int:pk>', views.editGroups, name="editGroups"),
path('editPassword/<int:pk>', views.editPassword, name="editPassword"), path('editPassword/<int:pk>', views.editPassword, name="editPassword"),
path('editUser/<int:pk>', views.editUser, name="editUser"), path('editUser/<int:pk>', views.editUser, name="editUser"),
path('resetPassword/<int:pk>', views.resetPassword, name="resetPassword"),
path('groupsIndex', views.groupsIndex, name="groupsIndex"), path('groupsIndex', views.groupsIndex, name="groupsIndex"),
path('groupProfile/<int:pk>', views.groupProfile, name="groupProfile"), path('groupProfile/<int:pk>', views.groupProfile, name="groupProfile"),
path('createGroup', views.createGroup, name="createGroup"), path('createGroup', views.createGroup, name="createGroup"),

View file

@ -282,23 +282,6 @@ def editUser(request, pk):
return redirect(reverse('users:profile', kwargs={'pk': pk})) return redirect(reverse('users:profile', kwargs={'pk': pk}))
return render(request, "form.html", {"form_entete":"Modification du compte " + user.username, "form": form, "form_title": "Modification des informations", "form_button": "Modifier", "form_button_icon": "pencil-alt"}) return render(request, "form.html", {"form_entete":"Modification du compte " + user.username, "form": form, "form_title": "Modification des informations", "form_button": "Modifier", "form_button_icon": "pencil-alt"})
@active_required
@login_required
@permission_required('auth.change_user')
def resetPassword(request, pk):
"""
Reset the password of a user (:class:`django.contrib.auth.models.User`).
"""
user = get_object_or_404(User, pk=pk)
if user.is_superuser:
messages.error(request, "Impossible de réinitialiser le mot de passe de " + user.username + " : il est superuser.")
return redirect(reverse('users:profile', kwargs={'pk': pk}))
else:
user.set_password(user.username)
user.save()
messages.success(request, "Le mot de passe de " + user.username + " a bien été réinitialisé.")
return redirect(reverse('users:profile', kwargs={'pk': pk}))
@active_required @active_required
@login_required @login_required
@permission_required('auth.view_user') @permission_required('auth.view_user')