admin: fix Password Recovery function not working

This commit is contained in:
Jens Langhammer 2020-07-01 12:10:12 +02:00
parent 02c1c434a2
commit 13084562c5
3 changed files with 12 additions and 5 deletions

View File

@ -5,8 +5,10 @@ from django.contrib.auth.mixins import (
PermissionRequiredMixin as DjangoPermissionRequiredMixin, PermissionRequiredMixin as DjangoPermissionRequiredMixin,
) )
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.urls import reverse, reverse_lazy from django.urls import reverse, reverse_lazy
from django.utils.http import urlencode
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.views.generic import DeleteView, DetailView, ListView, UpdateView from django.views.generic import DeleteView, DetailView, ListView, UpdateView
from guardian.mixins import ( from guardian.mixins import (
@ -80,7 +82,7 @@ class UserDeleteView(
success_url = reverse_lazy("passbook_admin:users") success_url = reverse_lazy("passbook_admin:users")
success_message = _("Successfully deleted User") 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) messages.success(self.request, self.success_message)
return super().delete(request, *args, **kwargs) return super().delete(request, *args, **kwargs)
@ -91,13 +93,13 @@ class UserPasswordResetView(LoginRequiredMixin, PermissionRequiredMixin, DetailV
model = User model = User
permission_required = "passbook_core.reset_user_password" 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""" """Create token for user and return link"""
super().get(request, *args, **kwargs) super().get(request, *args, **kwargs)
# TODO: create plan for user, get token
token = Token.objects.create(user=self.object) token = Token.objects.create(user=self.object)
querystring = urlencode({"token": token.token_uuid})
link = request.build_absolute_uri( link = request.build_absolute_uri(
reverse("passbook_flows:default-recovery", kwargs={"token": token.uuid}) reverse("passbook_flows:default-recovery") + f"?{querystring}"
) )
messages.success( messages.success(
request, _("Password reset link: <pre>%(link)s</pre>" % {"link": link}) request, _("Password reset link: <pre>%(link)s</pre>" % {"link": link})

View File

@ -5,7 +5,7 @@ from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.views import View from django.views import View
from django.views.generic import TemplateView 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 from passbook.audit.models import Event, EventAction

View File

@ -230,3 +230,8 @@ input[data-is-monospace] {
font-size: var(--pf-global--FontSize--2xl); font-size: var(--pf-global--FontSize--2xl);
font-family: monospace; font-family: monospace;
} }
/* Fix pre elements within alerts */
.pf-c-alert pre {
white-space: pre-wrap;
}