Repository: bookwyrm-social/bookwyrm

Issue:
Re-send confirmation page shows 404
**Describe the bug**
I signed up on bookwyrm.social, but didn't get my confirmation code over email. I requested it again on the confirmation page (had to write my email), and it went to https://bookwyrm.social/resend-link with a 404 page displaying instead.

**Expected behavior**
If I wrote an invalid email, tell me that. Otherwise the 404 page doesn't make much sense.

**Instance**
bookwyrm.social

---

**Desktop (please complete the following information):**
    - OS: macOS 12.3
    - Browser Firefox 98.0.1



Discussion:
That's definitely not the right behavior! Thanks for flagging. In the mean time, if you still haven't gotten your confirmation code, can you email me at mousereeve@riseup.net with the email or username you used to register your account? I can grab it for you
The culprit here is probably this:

https://github.com/bookwyrm-social/bookwyrm/blob/35e27a44434c5825072f32ef23a98a75a239ff13/bookwyrm/views/landing/register.py#L136

Entering an incorrect email immediately equals a 404 with no helpful message.
Off-topic: finally received the email at 2:33AM (so about a few hours late).
The delayed email is because of #2030 

Resolving patch:
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py
--- a/bookwyrm/urls.py
+++ b/bookwyrm/urls.py
@@ -71,7 +71,7 @@
         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
--- a/bookwyrm/views/__init__.py
+++ b/bookwyrm/views/__init__.py
@@ -52,7 +52,8 @@
 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
--- a/bookwyrm/views/landing/register.py
+++ b/bookwyrm/views/landing/register.py
@@ -5,7 +5,6 @@
 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 @@ def post(self, request):
         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}
+        )


Test patch:
diff --git a/bookwyrm/tests/views/landing/test_register.py b/bookwyrm/tests/views/landing/test_register.py
--- a/bookwyrm/tests/views/landing/test_register.py
+++ b/bookwyrm/tests/views/landing/test_register.py
@@ -360,10 +360,17 @@ def test_confirm_email_post(self, *_):
         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)