diff --git a/bookwyrm/templates/confirm_email/confirm_email.html b/bookwyrm/templates/confirm_email/confirm_email.html index 8c8adcdd..abdd3a73 100644 --- a/bookwyrm/templates/confirm_email/confirm_email.html +++ b/bookwyrm/templates/confirm_email/confirm_email.html @@ -29,9 +29,16 @@
- {% 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 00000000..221f0756 --- /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 id="resend-modal" %} +{% endblock %} diff --git a/bookwyrm/templates/confirm_email/resend_form.html b/bookwyrm/templates/confirm_email/resend_form.html deleted file mode 100644 index 7c0c1098..00000000 --- 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 00000000..beb9318a --- /dev/null +++ b/bookwyrm/templates/confirm_email/resend_modal.html @@ -0,0 +1,44 @@ +{% extends "components/modal.html" %} +{% load i18n %} + +{% block modal-title %} +{% trans "Resend confirmation link" %} +{% endblock %} + +{% block modal-form-open %} +
+{% endblock %} + +{% block modal-body %} +{% csrf_token %} +
+ +
+ + {% if error %} +
+

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

+
+ {% endif %} +
+
+{% endblock %} + +{% block modal-footer %} +
+ +
+{% endblock %} + +{% block modal-form-close %} +
+{% endblock %} diff --git a/bookwyrm/tests/views/landing/test_register.py b/bookwyrm/tests/views/landing/test_register.py index dd2c5e97..24360a64 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) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 040b479c..d73327f1 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 36423fee..eadf423d 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 86cd96ea..f9a3cecb 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,22 @@ 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} + )