From 4386d2ddb9b923a92c5fd0f5f1817faadb625055 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 19 Mar 2022 12:00:16 -0700 Subject: [PATCH 1/4] Switches resend email to modal --- .../confirm_email/confirm_email.html | 11 +++-- bookwyrm/templates/confirm_email/resend.html | 10 +++++ .../templates/confirm_email/resend_form.html | 20 --------- .../templates/confirm_email/resend_modal.html | 42 +++++++++++++++++++ bookwyrm/urls.py | 2 +- bookwyrm/views/__init__.py | 3 +- bookwyrm/views/landing/register.py | 28 ++++++++----- 7 files changed, 81 insertions(+), 35 deletions(-) create mode 100644 bookwyrm/templates/confirm_email/resend.html delete mode 100644 bookwyrm/templates/confirm_email/resend_form.html create mode 100644 bookwyrm/templates/confirm_email/resend_modal.html diff --git a/bookwyrm/templates/confirm_email/confirm_email.html b/bookwyrm/templates/confirm_email/confirm_email.html index 8c8adcdd9..65d40829f 100644 --- a/bookwyrm/templates/confirm_email/confirm_email.html +++ b/bookwyrm/templates/confirm_email/confirm_email.html @@ -29,9 +29,14 @@
- {% trans "Can't find your code?" as button_text %} - {% include "snippets/toggle/open_button.html" with text=button_text controls_text="resend_form" focus="resend_form_header" %} - {% include "confirm_email/resend_form.html" with controls_text="resend_form" %} + + {% include "confirm_email/resend_modal.html" with id="resend_form" %}
diff --git a/bookwyrm/templates/confirm_email/resend.html b/bookwyrm/templates/confirm_email/resend.html new file mode 100644 index 000000000..0b5ded068 --- /dev/null +++ b/bookwyrm/templates/confirm_email/resend.html @@ -0,0 +1,10 @@ +{% extends 'landing/layout.html' %} +{% load i18n %} + +{% block title %} +{% trans "Resend confirmation link" %} +{% endblock %} + +{% block content %} +{% include "confirm_email/resend_modal.html" with active=True static=True %} +{% endblock %} diff --git a/bookwyrm/templates/confirm_email/resend_form.html b/bookwyrm/templates/confirm_email/resend_form.html deleted file mode 100644 index 7c0c10980..000000000 --- a/bookwyrm/templates/confirm_email/resend_form.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends "components/inline_form.html" %} -{% load i18n %} -{% block header %} -{% trans "Resend confirmation link" %} -{% endblock %} - -{% block form %} -
- {% csrf_token %} -
- -
- -
-
-
- -
-
-{% endblock %} diff --git a/bookwyrm/templates/confirm_email/resend_modal.html b/bookwyrm/templates/confirm_email/resend_modal.html new file mode 100644 index 000000000..713fe6445 --- /dev/null +++ b/bookwyrm/templates/confirm_email/resend_modal.html @@ -0,0 +1,42 @@ +{% extends "components/modal.html" %} +{% load i18n %} + +{% block modal-title %} +{% trans "Resend confirmation link" %} +{% endblock %} + +{% block modal-form-open %} +
+{% endblock %} + +{% block modal-body %} +{% csrf_token %} +
+ +
+ +
+

+ {% trans "No user matching this email address found." %} +

+
+
+
+{% endblock %} + +{% block modal-footer %} +
+ +
+{% endblock %} + +{% block modal-form-close %} +
+{% endblock %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 040b479cd..d73327f15 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -71,7 +71,7 @@ urlpatterns = [ views.ConfirmEmailCode.as_view(), name="confirm-email-code", ), - re_path(r"^resend-link/?$", views.resend_link, name="resend-link"), + re_path(r"^resend-link/?$", views.ResendConfirmEmail.as_view(), name="resend-link"), re_path(r"^logout/?$", views.Logout.as_view(), name="logout"), re_path( r"^password-reset/?$", diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 36423feed..eadf423d2 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -52,7 +52,8 @@ from .books.links import BookFileLinks, AddFileLink, delete_link from .landing.about import about, privacy, conduct from .landing.landing import Home, Landing from .landing.login import Login, Logout -from .landing.register import Register, ConfirmEmail, ConfirmEmailCode, resend_link +from .landing.register import Register +from .landing.register import ConfirmEmail, ConfirmEmailCode, ResendConfirmEmail from .landing.password import PasswordResetRequest, PasswordReset # shelves diff --git a/bookwyrm/views/landing/register.py b/bookwyrm/views/landing/register.py index 86cd96ea9..681ce0a5e 100644 --- a/bookwyrm/views/landing/register.py +++ b/bookwyrm/views/landing/register.py @@ -5,7 +5,6 @@ from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View -from django.views.decorators.http import require_POST from django.views.decorators.debug import sensitive_variables, sensitive_post_parameters from bookwyrm import emailing, forms, models @@ -129,12 +128,21 @@ class ConfirmEmail(View): return ConfirmEmailCode().get(request, code) -@require_POST -def resend_link(request): - """resend confirmation link""" - email = request.POST.get("email") - user = get_object_or_404(models.User, email=email) - emailing.email_confirmation_email(user) - return TemplateResponse( - request, "confirm_email/confirm_email.html", {"valid": True} - ) +class ResendConfirmEmail(View): + """you probably didn't get the email because celery is slow but you can try this""" + def get(self, request, error=False): + """resend link landing page""" + return TemplateResponse(request, "confirm_email/resend.html", {"error": error}) + + def post(self, request): + """resend confirmation link""" + email = request.POST.get("email") + try: + user = models.User.objects.get(email=email) + except models.User.DoesNotExist: + return self.get(request, error=True) + + emailing.email_confirmation_email(user) + return TemplateResponse( + request, "confirm_email/confirm_email.html", {"valid": True} + ) From f2ab890b5af49d1d80583ca5c66dd799e4d986a8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 19 Mar 2022 12:07:07 -0700 Subject: [PATCH 2/4] Adds fallback form to modal --- .../templates/confirm_email/confirm_email.html | 16 +++++++++------- .../templates/confirm_email/resend_modal.html | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/confirm_email/confirm_email.html b/bookwyrm/templates/confirm_email/confirm_email.html index 65d40829f..abdd3a734 100644 --- a/bookwyrm/templates/confirm_email/confirm_email.html +++ b/bookwyrm/templates/confirm_email/confirm_email.html @@ -29,13 +29,15 @@
- +
+ +
{% include "confirm_email/resend_modal.html" with id="resend_form" %}
diff --git a/bookwyrm/templates/confirm_email/resend_modal.html b/bookwyrm/templates/confirm_email/resend_modal.html index 713fe6445..beb9318a9 100644 --- a/bookwyrm/templates/confirm_email/resend_modal.html +++ b/bookwyrm/templates/confirm_email/resend_modal.html @@ -22,11 +22,13 @@ aria-described-by="id_email_errors" required > + {% if error %}

{% trans "No user matching this email address found." %}

+ {% endif %} {% endblock %} From 78ac252daecf813b6c1a51e9c6ff3aa29d94008d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 19 Mar 2022 12:08:57 -0700 Subject: [PATCH 3/4] Python formatting --- bookwyrm/views/landing/register.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/views/landing/register.py b/bookwyrm/views/landing/register.py index 681ce0a5e..f9a3cecb8 100644 --- a/bookwyrm/views/landing/register.py +++ b/bookwyrm/views/landing/register.py @@ -130,6 +130,7 @@ class ConfirmEmail(View): class ResendConfirmEmail(View): """you probably didn't get the email because celery is slow but you can try this""" + def get(self, request, error=False): """resend link landing page""" return TemplateResponse(request, "confirm_email/resend.html", {"error": error}) From 1b53c81351b1d952e666e5a8d3ff43d6fb059d07 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 19 Mar 2022 15:16:20 -0700 Subject: [PATCH 4/4] Updates tests --- bookwyrm/templates/confirm_email/resend.html | 2 +- bookwyrm/tests/views/landing/test_register.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/confirm_email/resend.html b/bookwyrm/templates/confirm_email/resend.html index 0b5ded068..221f07565 100644 --- a/bookwyrm/templates/confirm_email/resend.html +++ b/bookwyrm/templates/confirm_email/resend.html @@ -6,5 +6,5 @@ {% endblock %} {% block content %} -{% include "confirm_email/resend_modal.html" with active=True static=True %} +{% include "confirm_email/resend_modal.html" with active=True static=True id="resend-modal" %} {% endblock %} diff --git a/bookwyrm/tests/views/landing/test_register.py b/bookwyrm/tests/views/landing/test_register.py index dd2c5e971..24360a646 100644 --- a/bookwyrm/tests/views/landing/test_register.py +++ b/bookwyrm/tests/views/landing/test_register.py @@ -360,10 +360,17 @@ class RegisterViews(TestCase): result = view(request) validate_html(result.render()) - def test_resend_link(self, *_): + def test_resend_link_get(self, *_): + """try again""" + request = self.factory.get("") + request.user = self.anonymous_user + result = views.ResendConfirmEmail.as_view()(request) + validate_html(result.render()) + + def test_resend_link_post(self, *_): """try again""" request = self.factory.post("", {"email": "mouse@mouse.com"}) request.user = self.anonymous_user with patch("bookwyrm.emailing.send_email.delay") as mock: - views.resend_link(request) + views.ResendConfirmEmail.as_view()(request) self.assertEqual(mock.call_count, 1)