mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-07 10:58:25 +02:00
Add password change view (#168)
This commit is contained in:
21
bookmarks/templates/registration/password_change_done.html
Normal file
21
bookmarks/templates/registration/password_change_done.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{% extends 'bookmarks/layout.html' %}
|
||||||
|
{% load widget_tweaks %}
|
||||||
|
|
||||||
|
{% block title %}Password changed{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="auth-page">
|
||||||
|
<div class="columns">
|
||||||
|
<section class="content-area column col-5 col-md-12">
|
||||||
|
<div class="content-area-header">
|
||||||
|
<h2>Password Changed</h2>
|
||||||
|
</div>
|
||||||
|
<p class="text-success">
|
||||||
|
Your password was changed successfully.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
55
bookmarks/templates/registration/password_change_form.html
Normal file
55
bookmarks/templates/registration/password_change_form.html
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
{% extends 'bookmarks/layout.html' %}
|
||||||
|
{% load widget_tweaks %}
|
||||||
|
|
||||||
|
{% block title %}Change Password{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="auth-page">
|
||||||
|
<div class="columns">
|
||||||
|
<section class="content-area column col-5 col-md-12">
|
||||||
|
<div class="content-area-header">
|
||||||
|
<h2>Change Password</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post" action="{% url 'change_password' %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="form-group {% if form.old_password.errors %}has-error{% endif %}">
|
||||||
|
<label class="form-label" for="{{ form.old_password.id_for_label }}">Old password</label>
|
||||||
|
{{ form.old_password|add_class:'form-input'|attr:"placeholder: " }}
|
||||||
|
{% if form.old_password.errors %}
|
||||||
|
<div class="form-input-hint">
|
||||||
|
{{ form.old_password.errors }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="form-group {% if form.new_password1.errors %}has-error{% endif %}">
|
||||||
|
<label class="form-label" for="{{ form.new_password1.id_for_label }}">New password</label>
|
||||||
|
{{ form.new_password1|add_class:'form-input'|attr:"placeholder: " }}
|
||||||
|
{% if form.new_password1.errors %}
|
||||||
|
<div class="form-input-hint">
|
||||||
|
{{ form.new_password1.errors }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="form-group {% if form.new_password2.errors %}has-error{% endif %}">
|
||||||
|
<label class="form-label" for="{{ form.new_password2.id_for_label }}">Confirm new password</label>
|
||||||
|
{{ form.new_password2|add_class:'form-input'|attr:"placeholder: " }}
|
||||||
|
{% if form.new_password2.errors %}
|
||||||
|
<div class="form-input-hint">
|
||||||
|
{{ form.new_password2.errors }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column col-3">
|
||||||
|
<input type="submit" value="Change Password" class="btn btn-primary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
@@ -9,6 +9,9 @@
|
|||||||
{# Profile section #}
|
{# Profile section #}
|
||||||
<section class="content-area">
|
<section class="content-area">
|
||||||
<h2>Profile</h2>
|
<h2>Profile</h2>
|
||||||
|
<p>
|
||||||
|
<a href="{% url 'change_password' %}">Change password</a>
|
||||||
|
</p>
|
||||||
<form action="{% url 'bookmarks:settings.general' %}" method="post" novalidate>
|
<form action="{% url 'bookmarks:settings.general' %}" method="post" novalidate>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
55
bookmarks/tests/test_password_change_view.py
Normal file
55
bookmarks/tests/test_password_change_view.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
||||||
|
|
||||||
|
|
||||||
|
class PasswordChangeViewTestCase(TestCase, BookmarkFactoryMixin):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.user = User.objects.create_user('testuser', 'test@example.com', 'initial_password')
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
|
||||||
|
def test_change_password(self):
|
||||||
|
form_data = {
|
||||||
|
'old_password': 'initial_password',
|
||||||
|
'new_password1': 'new_password',
|
||||||
|
'new_password2': 'new_password',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(reverse('change_password'), form_data)
|
||||||
|
|
||||||
|
self.assertRedirects(response, reverse('password_change_done'))
|
||||||
|
|
||||||
|
def test_change_password_done(self):
|
||||||
|
form_data = {
|
||||||
|
'old_password': 'initial_password',
|
||||||
|
'new_password1': 'new_password',
|
||||||
|
'new_password2': 'new_password',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(reverse('change_password'), form_data, follow=True)
|
||||||
|
|
||||||
|
self.assertContains(response, 'Your password was changed successfully')
|
||||||
|
|
||||||
|
def test_should_return_error_for_invalid_old_password(self):
|
||||||
|
form_data = {
|
||||||
|
'old_password': 'wrong_password',
|
||||||
|
'new_password1': 'new_password',
|
||||||
|
'new_password2': 'new_password',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(reverse('change_password'), form_data)
|
||||||
|
|
||||||
|
self.assertIn('old_password', response.context_data['form'].errors)
|
||||||
|
|
||||||
|
def test_should_return_error_for_mismatching_new_password(self):
|
||||||
|
form_data = {
|
||||||
|
'old_password': 'initial_password',
|
||||||
|
'new_password1': 'new_password',
|
||||||
|
'new_password2': 'wrong_password',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(reverse('change_password'), form_data)
|
||||||
|
|
||||||
|
self.assertIn('new_password2', response.context_data['form'].errors)
|
@@ -25,11 +25,14 @@ urlpatterns = [
|
|||||||
extra_context=dict(allow_registration=ALLOW_REGISTRATION)),
|
extra_context=dict(allow_registration=ALLOW_REGISTRATION)),
|
||||||
name='login'),
|
name='login'),
|
||||||
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
|
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
|
||||||
|
path('change-password/', auth_views.PasswordChangeView.as_view(), name='change_password'),
|
||||||
|
path('password-change-done/', auth_views.PasswordChangeDoneView.as_view(), name='password_change_done'),
|
||||||
path('', include('bookmarks.urls')),
|
path('', include('bookmarks.urls')),
|
||||||
]
|
]
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
import debug_toolbar
|
import debug_toolbar
|
||||||
|
|
||||||
urlpatterns.append(path('__debug__/', include(debug_toolbar.urls)))
|
urlpatterns.append(path('__debug__/', include(debug_toolbar.urls)))
|
||||||
|
|
||||||
if ALLOW_REGISTRATION:
|
if ALLOW_REGISTRATION:
|
||||||
|
Reference in New Issue
Block a user