From 8b99264aef42e6531c614bb7ea73d94b2ed48bef Mon Sep 17 00:00:00 2001 From: CelineDknp Date: Wed, 9 Jan 2019 21:12:13 +0100 Subject: [PATCH] Working on the change of password --- .../haitiwater/apps/authentication/exports.py | 7 +++ code/haitiwater/apps/authentication/forms.py | 8 ++++ .../authentication/templates/password.html | 27 ++++++++++++ .../templates/password_changed.html | 23 ++++++++++ .../authentication/templates/profile.html | 43 +------------------ code/haitiwater/apps/authentication/urls.py | 10 ++++- code/haitiwater/haitiwater/urls.py | 1 + 7 files changed, 76 insertions(+), 43 deletions(-) create mode 100644 code/haitiwater/apps/authentication/forms.py create mode 100644 code/haitiwater/apps/authentication/templates/password.html create mode 100644 code/haitiwater/apps/authentication/templates/password_changed.html diff --git a/code/haitiwater/apps/authentication/exports.py b/code/haitiwater/apps/authentication/exports.py index 89ab479..647ef04 100644 --- a/code/haitiwater/apps/authentication/exports.py +++ b/code/haitiwater/apps/authentication/exports.py @@ -11,6 +11,13 @@ from django.contrib.contenttypes.models import ContentType from ..authentication.models import Profile from ..water_network.models import Zone + +def edit(request): + print(request.POST) + + return HttpResponse(status=200) + + @csrf_exempt #TODO : this is a hot fix for something I don't understand, remove to debug def connect(request): print("Connection !") diff --git a/code/haitiwater/apps/authentication/forms.py b/code/haitiwater/apps/authentication/forms.py new file mode 100644 index 0000000..fe12daf --- /dev/null +++ b/code/haitiwater/apps/authentication/forms.py @@ -0,0 +1,8 @@ +from django.contrib.auth.forms import PasswordChangeForm +from django import forms + + +class CustomPasswordChangeForm(PasswordChangeForm): + old_password = forms.PasswordInput() + new_password1 = forms.PasswordInput + new_password2 = forms.PasswordInput diff --git a/code/haitiwater/apps/authentication/templates/password.html b/code/haitiwater/apps/authentication/templates/password.html new file mode 100644 index 0000000..b0d52b9 --- /dev/null +++ b/code/haitiwater/apps/authentication/templates/password.html @@ -0,0 +1,27 @@ +{% extends "base.html" %} +{% load static %} + +{% block page_name %} + + Profil de {{ user.get_username }} +{% endblock %} + +{% block page_content %} +
+
+
+
+ +
+

Changer le mot de passe

+
+
+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/code/haitiwater/apps/authentication/templates/password_changed.html b/code/haitiwater/apps/authentication/templates/password_changed.html new file mode 100644 index 0000000..35d06ee --- /dev/null +++ b/code/haitiwater/apps/authentication/templates/password_changed.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} +{% load static %} + +{% block page_name %} + + Profil de {{ user.get_username }} +{% endblock %} + +{% block page_content %} +
+
+
+
+ +
+

Mot de passe bien modifié

+
+
+ Votre mot de passe a bien été changé. Veuillez vous reconnecter +
+
+
+{% endblock %} \ No newline at end of file diff --git a/code/haitiwater/apps/authentication/templates/profile.html b/code/haitiwater/apps/authentication/templates/profile.html index 4f94b10..f902906 100644 --- a/code/haitiwater/apps/authentication/templates/profile.html +++ b/code/haitiwater/apps/authentication/templates/profile.html @@ -17,7 +17,7 @@

Informations

-
+ {% csrf_token %}
@@ -63,47 +63,8 @@
-

Changer le mot de passe

+

Changer le mot de passe

-
- - {% csrf_token %} -
- -
-
- - - - -
-
-
-
- -
-
- - - - -
-
-
-
- -
-
- - - - -
-
-
- - -
{% endblock %} \ No newline at end of file diff --git a/code/haitiwater/apps/authentication/urls.py b/code/haitiwater/apps/authentication/urls.py index 5f757c8..6ea99e4 100644 --- a/code/haitiwater/apps/authentication/urls.py +++ b/code/haitiwater/apps/authentication/urls.py @@ -1,10 +1,16 @@ +from django.conf.urls import url from django.urls import path - +from django.contrib.auth import views as auth_views +from . import forms from . import views from . import exports urlpatterns = [ - path('connect/', exports.connect, name='auth'), + url(r'^editer/changer-mot-de-passe/$', auth_views.PasswordChangeView.as_view(template_name='password.html'), + name="change"), + url(r'^editer/changer-mot-de-passe/fait/$', auth_views.PasswordChangeDoneView.as_view( + template_name='password_changed.html'), name="changedone"), path('editer/', views.profile, name='profile'), + path('editer/infos/', exports.edit, name='profile'), path('', views.index, name='auth'), ] diff --git a/code/haitiwater/haitiwater/urls.py b/code/haitiwater/haitiwater/urls.py index 27aae8d..dc59fbe 100644 --- a/code/haitiwater/haitiwater/urls.py +++ b/code/haitiwater/haitiwater/urls.py @@ -38,5 +38,6 @@ urlpatterns += [ url(r'^login/$', auth_views.LoginView.as_view(template_name='authentication.html'), name='login'), url(r'^logout/$', auth_views.LogoutView.as_view(), name='logout'), + url(r'^login/recuperer-mot-de-passe/$', auth_views.PasswordResetView.as_view(), name="reset"), url(r'^admin/', admin.site.urls), ]