Crash de la vue pour changer de mot de passe #32
4 changed files with 42 additions and 13 deletions
|
@ -10,16 +10,15 @@
|
|||
|
||||
<div class="6u 12u$(small)">
|
||||
<h2>{% trans "Changement du mot de passe" %} :</h2>
|
||||
{% if error %}
|
||||
<p>{{ error }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% if success %}
|
||||
<p>{% trans "Changement enregistré" %} !</p>
|
||||
<p>{% trans "Changement enregistré" %} !</p>
|
||||
{% endif %}
|
||||
|
||||
<form action="{% url 'change_password' %}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="{% trans "Valider" %}" />   <a href="{% url 'change_membre' %}" class="button alt">{% trans "Retour" %}</a>
|
||||
<input type="submit" value="{% trans "Valider" %}" /> <a href="{% url 'change_membre' %}" class="button alt">{% trans "Retour" %}</a>
|
||||
</form>
|
||||
</div></div></div></section></div>
|
||||
{% endblock %}
|
||||
|
|
0
gestion/tests/__init__.py
Normal file
0
gestion/tests/__init__.py
Normal file
32
gestion/tests/test_views.py
Normal file
32
gestion/tests/test_views.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class TestPasswordChangeView(TestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create_user("alice", password="changeme")
|
||||
self.url = reverse("change_password")
|
||||
|
||||
def test_get(self):
|
||||
client = Client()
|
||||
client.force_login(self.user)
|
||||
resp = client.get(self.url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
def test_post(self):
|
||||
client = Client()
|
||||
client.force_login(self.user)
|
||||
|
||||
data = {
|
||||
"old_password": "changeme",
|
||||
"new_password1": "s3cr3tp4ss",
|
||||
"new_password2": "s3cr3tp4ss",
|
||||
}
|
||||
resp = client.post(self.url, data)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
client.logout()
|
||||
self.assertTrue(client.login(username="alice", password="s3cr3tp4ss"))
|
|
@ -63,22 +63,20 @@ def change_membre(request):
|
|||
user_form = ChangeFormUser(instance=request.user)
|
||||
return render(request, 'gestion/change.html', locals())
|
||||
|
||||
|
||||
@login_required
|
||||
def change_password(request):
|
||||
success = False
|
||||
if request.method == 'POST':
|
||||
requbis = request.POST.copy()
|
||||
form = PasswordChangeForm(request.user, data=requbis)
|
||||
form = PasswordChangeForm(request.user, data=request.POST)
|
||||
if form.is_valid():
|
||||
|
||||
request.user.profile.photo.delete()
|
||||
form.save()
|
||||
|
||||
success = True
|
||||
|
||||
else:
|
||||
form = PasswordChangeForm(request.user)
|
||||
return render(request, 'gestion/changepasswd.html', locals())
|
||||
|
||||
return render(
|
||||
request, 'gestion/changepasswd.html', {"form": form, "success": success}
|
||||
)
|
||||
|
||||
|
||||
def inscription_membre(request):
|
||||
|
|
Loading…
Reference in a new issue