summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog/en/changelog_2022-06-15.md1
-rw-r--r--changelog/fr/changelog_2023-01-25.md1
-rw-r--r--ishtar_common/forms_common.py35
-rw-r--r--ishtar_common/templates/registration/password_change_done.html8
-rw-r--r--ishtar_common/templates/registration/password_change_form.html36
-rw-r--r--ishtar_common/urls_registration.py4
-rw-r--r--ishtar_common/views.py7
7 files changed, 68 insertions, 24 deletions
diff --git a/changelog/en/changelog_2022-06-15.md b/changelog/en/changelog_2022-06-15.md
index 946e3614c..c2171b440 100644
--- a/changelog/en/changelog_2022-06-15.md
+++ b/changelog/en/changelog_2022-06-15.md
@@ -3,6 +3,7 @@ v4.0.54 - 2099-12-31
### Features/improvements ###
- wizards: automatic scroll on field when navigating with TAB key
+- update password form: improve layout - redirect to start page
v4.0.53 - 2023-07-06
diff --git a/changelog/fr/changelog_2023-01-25.md b/changelog/fr/changelog_2023-01-25.md
index e804e85d1..f9780efb1 100644
--- a/changelog/fr/changelog_2023-01-25.md
+++ b/changelog/fr/changelog_2023-01-25.md
@@ -3,6 +3,7 @@ v4.0.54 - 2099-12-31
### Fonctionnalités/améliorations ###
- `wizards` : défilement automatique sur le champ lorsque l'on navigue avec la touche TAB
+- formulaire de mise à jour mot de passe : amélioration de la présentation - redirection vers la page d'accueil
v4.0.53 - 2023-07-06
--------------------
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index ce7f81f34..9e29f35e1 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
@@ -31,9 +31,12 @@ import zipfile
from django import forms
from django.conf import settings
+from django.contrib.auth import password_validation
from django.contrib.auth.models import User
-from django.contrib.auth.forms import AuthenticationForm as AuthAuthenticationForm, \
- UsernameField
+from django.contrib.auth.forms import UsernameField, \
+ AuthenticationForm as AuthAuthenticationForm, \
+ PasswordChangeForm as AuthPasswordChangeForm, \
+ SetPasswordForm as AuthSetPasswordForm
from django.contrib.contenttypes.models import ContentType
from django.core import validators
from django.core.cache import cache
@@ -149,6 +152,32 @@ class AuthenticationForm(AuthAuthenticationForm):
)
+class SetPasswordForm(AuthSetPasswordForm):
+ new_password1 = forms.CharField(
+ label=_("New password"),
+ strip=False,
+ help_text=password_validation.password_validators_help_text_html(),
+ widget=forms.PasswordInput(attrs={'autocomplete': 'off',
+ 'data-toggle': 'password'}),
+ )
+ new_password2 = forms.CharField(
+ label=_("New password confirmation"),
+ strip=False,
+ widget=forms.PasswordInput(attrs={'autocomplete': 'off',
+ 'data-toggle': 'password'}),
+ )
+
+
+class PasswordChangeForm(SetPasswordForm, AuthPasswordChangeForm):
+ old_password = forms.CharField(
+ label=_("Old password"),
+ strip=False,
+ widget=forms.PasswordInput(attrs={'autofocus': True, 'autocomplete': 'off',
+ 'data-toggle': 'password'}),
+
+ )
+
+
class NewItemForm(forms.Form):
def __init__(self, *args, **kwargs):
self.limits = {}
diff --git a/ishtar_common/templates/registration/password_change_done.html b/ishtar_common/templates/registration/password_change_done.html
deleted file mode 100644
index 9d442360c..000000000
--- a/ishtar_common/templates/registration/password_change_done.html
+++ /dev/null
@@ -1,8 +0,0 @@
-{% extends "base.html" %}
-{% load i18n %}
-
-{% block content %}
-<div class='info'>
-<p>{% trans "Password changed" %}</p>
-</div>
-{% endblock %}
diff --git a/ishtar_common/templates/registration/password_change_form.html b/ishtar_common/templates/registration/password_change_form.html
index 84d915eaa..deb7af503 100644
--- a/ishtar_common/templates/registration/password_change_form.html
+++ b/ishtar_common/templates/registration/password_change_form.html
@@ -2,13 +2,33 @@
{% load i18n %}
{% block content %}
-<div class='form'>
-<form method="post" action=".">{% csrf_token %}
- <table>
- {{ form.as_table }}
+<div class="container">
+ <div class="row justify-content-center">
+ <div class="col-lg-4 col-md-6 col-sm-10">
+ <h3 class="text-center">{% trans "Change password" %}</h3>
+ <form method="post" action=".">{% csrf_token %}
+ {% if form.non_field_errors %}
+ <div class="form-group row">
+ {% for error in form.non_field_errors %}
+ <div class="form-group has-errors text-danger small">
+ {{error}}
+ </div>
+ {% endfor %}
+ </div>
+ {% endif %}
+ {% with force_large_col=True %}
+ {% for field in form %}
+ {% include "blocks/bs_field_snippet.html" %}
+ {% endfor %}
+ {% endwith %}
- <tr><td colspan='2'><input type="submit" value="{% trans 'Submit' %}" /></td></tr>
- </table>
-</form>
-</p>
+ <div class="row justify-content-center">
+ <div class="col-4">
+ <button type="submit" class="btn btn-primary">{% trans 'Validate' %}</button>
+ </div>
+ </div>
+ </form>
+ </div>
+ </div>
+</div>
{% endblock %}
diff --git a/ishtar_common/urls_registration.py b/ishtar_common/urls_registration.py
index 29d0055d7..085af2f87 100644
--- a/ishtar_common/urls_registration.py
+++ b/ishtar_common/urls_registration.py
@@ -40,12 +40,8 @@ urlpatterns = [
# url("^accounts/", include('django.contrib.auth.urls')),
path('accounts/login/', views.LoginView.as_view(), name='login'),
path('accounts/logout/', views.LogoutView.as_view(), name='logout'),
-
path('accounts/password_change/', views.PasswordChangeView.as_view(),
name='password_change'),
- path('accounts/password_change/done/', auth_views.PasswordChangeDoneView.as_view(),
- name='password_change_done'),
-
path('accounts/password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'),
path('accounts/password_reset/done/', auth_views.PasswordResetDoneView.as_view(),
name='password_reset_done'),
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 3f060f2e1..c10da588a 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -30,6 +30,7 @@ import urllib.parse
from django.apps import apps
from django.conf import settings
+from django.contrib import messages
from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import redirect_to_login, LoginView as AuthLoginView, \
@@ -67,7 +68,7 @@ from archaeological_warehouse.models import Warehouse
from ishtar_common import forms_common as forms
from ishtar_common import wizards
from ishtar_common.data_importer import ImporterError
-from ishtar_common.forms import FinalForm, FinalDeleteForm
+from ishtar_common.forms import FinalForm, FinalDeleteForm, reverse_lazy
from ishtar_common.models import get_current_profile
from ishtar_common.templatetags.link_to_window import simple_link_to_window
from ishtar_common.utils import (
@@ -200,9 +201,13 @@ def update_password_last_update(user):
class PasswordChangeView(AuthPasswordChangeView):
+ form_class = forms.PasswordChangeForm
+ success_url = reverse_lazy('start')
+
def form_valid(self, form):
returned = super().form_valid(form)
update_password_last_update(form.user)
+ messages.add_message(self.request, messages.INFO, _("Password changed"))
return returned