Fix: changement du mot de passe
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Departement(models.Model):
|
||||
"""Modèle représentant un département de l'entreprise."""
|
||||
nom = models.CharField(max_length=100)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from django.urls import path
|
||||
from .views import login_view, deconnexion_view
|
||||
|
||||
from .views import deconnexion_view, login_view, modifier_mot_passe
|
||||
|
||||
urlpatterns = [
|
||||
path('login/', login_view, name='login'),
|
||||
path('deconnexion/', deconnexion_view, name='deconnexion'),
|
||||
path('modifier-mot-de-passe/', modifier_mot_passe, name='modifier_mot_passe')
|
||||
]
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import json
|
||||
|
||||
from decouple import config
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.contrib.auth.models import User
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
||||
def login_view(request):
|
||||
@@ -18,6 +23,28 @@ def login_view(request):
|
||||
return render(request, 'authentification/login.html', {'error': 'Identifiants invalides'})
|
||||
return render(request, 'authentification/login.html')
|
||||
|
||||
@csrf_exempt
|
||||
def modifier_mot_passe(request):
|
||||
"""Vue pour permettre à un utilisateur de modifier son mot de passe et ses informations de profil"""
|
||||
|
||||
data = json.loads(request.body)
|
||||
ancien_mdp = data.get('ancien_mdp')
|
||||
nouveau_mdp = data.get('nouveau_mdp')
|
||||
confirmation_mdp = data.get('confirmation_mdp')
|
||||
username = data.get("username")
|
||||
|
||||
user = User.objects.get(username=username)
|
||||
|
||||
if not user.check_password(ancien_mdp):
|
||||
return JsonResponse({"error": "Le mot de passe actuel est incorrect."}, status=400)
|
||||
|
||||
if nouveau_mdp != confirmation_mdp:
|
||||
return JsonResponse({"error": "Le nouveau mot de passe et sa confirmation ne correspondent pas."}, status=400)
|
||||
|
||||
user.set_password(nouveau_mdp)
|
||||
user.save()
|
||||
return JsonResponse({"success": "Mot de passe modifié avec succès."})
|
||||
|
||||
def deconnexion_view(request):
|
||||
"""Gère la déconnexion de l'utilisateur."""
|
||||
logout(request)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.2/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from decouple import config
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user