summaryrefslogtreecommitdiff
path: root/ishtar_common/views.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-07-07 17:45:51 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-07-07 17:51:04 +0200
commit939bb82df4a993502d39bfb852b348547746cafa (patch)
tree324e5c416b8fa34d82012a4f74e28bac2cb132f2 /ishtar_common/views.py
parent1c299abec0ed2a562572ee2c4bdaf85d0c451148 (diff)
downloadIshtar-939bb82df4a993502d39bfb852b348547746cafa.tar.bz2
Ishtar-939bb82df4a993502d39bfb852b348547746cafa.zip
✨ enable password recovering by email
Diffstat (limited to 'ishtar_common/views.py')
-rw-r--r--ishtar_common/views.py42
1 files changed, 33 insertions, 9 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 38fd80689..2a60bfd6a 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -38,10 +38,7 @@ 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, \
- PasswordChangeView as AuthPasswordChangeView, \
- PasswordResetConfirmView as AuthPasswordResetConfirmView, \
- LogoutView as AuthLogoutView
+from django.contrib.auth import views as auth_view
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.core.cache import cache
@@ -179,7 +176,7 @@ def index(request):
return render(request, "index.html", dct)
-class LoginView(AuthLoginView):
+class LoginView(auth_view.LoginView):
form_class = forms.AuthenticationForm
def get_context_data(self, **kwargs):
@@ -188,7 +185,7 @@ class LoginView(AuthLoginView):
return context
-class LogoutView(AuthLogoutView):
+class LogoutView(auth_view.LogoutView):
def get(self, request, *args, **kwargs):
# clear cache
keys = []
@@ -210,7 +207,7 @@ def update_password_last_update(user):
cache.set(key, False, settings.CACHE_TIMEOUT)
-class PasswordChangeView(AuthPasswordChangeView):
+class PasswordChangeView(auth_view.PasswordChangeView):
form_class = forms.PasswordChangeForm
success_url = reverse_lazy('start')
template_name = 'registration/form.html'
@@ -227,10 +224,19 @@ class PasswordChangeView(AuthPasswordChangeView):
return context
-class PasswordResetConfirmView(AuthPasswordResetConfirmView):
+class PasswordResetConfirmView(auth_view.PasswordResetConfirmView):
+ form_class = forms.SetPasswordForm
+ success_url = reverse_lazy('login')
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context["page_title"] = _("Password reset")
+ return context
+
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
@@ -247,6 +253,24 @@ class RegistrationView(registration_views.RegistrationView):
raise NotImplementedError
+class PasswordResetView(auth_view.PasswordResetView):
+ template_name = 'registration/form.html'
+ success_url = reverse_lazy('start')
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context["page_title"] = _("Reset password")
+ return context
+
+ def form_valid(self, form):
+ returned = super().form_valid(form)
+ messages.add_message(
+ self.request, messages.INFO,
+ _("Email with password reset instructions has been sent.")
+ )
+ return returned
+
+
person_search_wizard = wizards.PersonSearch.as_view(
[("general-person_search", forms.PersonFormSelection)],
label=_("Person search"),
@@ -2753,7 +2777,7 @@ class DisplayItemView(IshtarMixin, TemplateView):
def dispatch(self, request, *args, **kwargs):
if not self.request.user.is_authenticated:
- return redirect_to_login(reverse("display-item", kwargs=kwargs))
+ return auth_view.redirect_to_login(reverse("display-item", kwargs=kwargs))
return super(DisplayItemView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, *args, **kwargs):