From 13084562c529c94733ffad8b48f571621b565c07 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 1 Jul 2020 12:10:12 +0200 Subject: [PATCH] admin: fix Password Recovery function not working --- passbook/admin/views/users.py | 10 ++++++---- passbook/stages/otp_static/views.py | 2 +- passbook/static/static/passbook/pf.css | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/passbook/admin/views/users.py b/passbook/admin/views/users.py index 6acca6863..6b010aea4 100644 --- a/passbook/admin/views/users.py +++ b/passbook/admin/views/users.py @@ -5,8 +5,10 @@ from django.contrib.auth.mixins import ( PermissionRequiredMixin as DjangoPermissionRequiredMixin, ) from django.contrib.messages.views import SuccessMessageMixin +from django.http import HttpRequest, HttpResponse from django.shortcuts import redirect from django.urls import reverse, reverse_lazy +from django.utils.http import urlencode from django.utils.translation import ugettext as _ from django.views.generic import DeleteView, DetailView, ListView, UpdateView from guardian.mixins import ( @@ -80,7 +82,7 @@ class UserDeleteView( success_url = reverse_lazy("passbook_admin:users") success_message = _("Successfully deleted User") - def delete(self, request, *args, **kwargs): + def delete(self, request: HttpRequest, *args, **kwargs) -> HttpResponse: messages.success(self.request, self.success_message) return super().delete(request, *args, **kwargs) @@ -91,13 +93,13 @@ class UserPasswordResetView(LoginRequiredMixin, PermissionRequiredMixin, DetailV model = User permission_required = "passbook_core.reset_user_password" - def get(self, request, *args, **kwargs): + def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse: """Create token for user and return link""" super().get(request, *args, **kwargs) - # TODO: create plan for user, get token token = Token.objects.create(user=self.object) + querystring = urlencode({"token": token.token_uuid}) link = request.build_absolute_uri( - reverse("passbook_flows:default-recovery", kwargs={"token": token.uuid}) + reverse("passbook_flows:default-recovery") + f"?{querystring}" ) messages.success( request, _("Password reset link:
%(link)s
" % {"link": link}) diff --git a/passbook/stages/otp_static/views.py b/passbook/stages/otp_static/views.py index a73eeb0cf..c3bf9a4db 100644 --- a/passbook/stages/otp_static/views.py +++ b/passbook/stages/otp_static/views.py @@ -5,7 +5,7 @@ from django.http import HttpRequest, HttpResponse from django.shortcuts import redirect from django.views import View from django.views.generic import TemplateView -from django_otp.plugins.otp_static.models import StaticToken, StaticDevice +from django_otp.plugins.otp_static.models import StaticDevice, StaticToken from passbook.audit.models import Event, EventAction diff --git a/passbook/static/static/passbook/pf.css b/passbook/static/static/passbook/pf.css index cafeba240..5f18d0cd6 100644 --- a/passbook/static/static/passbook/pf.css +++ b/passbook/static/static/passbook/pf.css @@ -230,3 +230,8 @@ input[data-is-monospace] { font-size: var(--pf-global--FontSize--2xl); font-family: monospace; } + +/* Fix pre elements within alerts */ +.pf-c-alert pre { + white-space: pre-wrap; +}