mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 03:13:12 +00:00
Unique email
This commit is contained in:
parent
8fe2008c7c
commit
b5a1df1271
5 changed files with 6 additions and 23 deletions
|
@ -21,6 +21,12 @@ class CreateUserForm(forms.ModelForm):
|
|||
|
||||
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):
|
||||
"""
|
||||
Form to create a new group (:class:`django.contrib.auth.models.Group`).
|
||||
|
|
|
@ -8,8 +8,6 @@ from preferences.models import PaymentMethod, Cotisation
|
|||
from gestion.models import ConsumptionHistory
|
||||
|
||||
|
||||
User._meta.get_field('email')._unique = True
|
||||
|
||||
class School(models.Model):
|
||||
"""
|
||||
Stores school.
|
||||
|
|
|
@ -58,9 +58,6 @@
|
|||
{% 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>
|
||||
{% 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 %}
|
||||
<span class="tabulation"><a href="{% url 'users:editGroups' user.pk %}"><i class="fa fa-layer-group"></i> Changer les groupes</a></span>
|
||||
{% endif %}
|
||||
|
|
|
@ -14,7 +14,6 @@ urlpatterns = [
|
|||
path('editGroups/<int:pk>', views.editGroups, name="editGroups"),
|
||||
path('editPassword/<int:pk>', views.editPassword, name="editPassword"),
|
||||
path('editUser/<int:pk>', views.editUser, name="editUser"),
|
||||
path('resetPassword/<int:pk>', views.resetPassword, name="resetPassword"),
|
||||
path('groupsIndex', views.groupsIndex, name="groupsIndex"),
|
||||
path('groupProfile/<int:pk>', views.groupProfile, name="groupProfile"),
|
||||
path('createGroup', views.createGroup, name="createGroup"),
|
||||
|
|
|
@ -282,23 +282,6 @@ def editUser(request, 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"})
|
||||
|
||||
@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
|
||||
@login_required
|
||||
@permission_required('auth.view_user')
|
||||
|
|
Loading…
Reference in a new issue