Switches resend email to modal

This commit is contained in:
Mouse Reeve 2022-03-19 12:00:16 -07:00
parent dc9f8fccb7
commit 4386d2ddb9
7 changed files with 81 additions and 35 deletions

View file

@ -29,9 +29,14 @@
</section> </section>
<section class="block"> <section class="block">
{% trans "Can't find your code?" as button_text %} <button
{% include "snippets/toggle/open_button.html" with text=button_text controls_text="resend_form" focus="resend_form_header" %} type="button"
{% include "confirm_email/resend_form.html" with controls_text="resend_form" %} class="button"
data-modal-open="resend_form"
>
{% trans "Can't find your code?" %}
</button>
{% include "confirm_email/resend_modal.html" with id="resend_form" %}
</section> </section>
</div> </div>
</div> </div>

View file

@ -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 %}

View file

@ -1,20 +0,0 @@
{% extends "components/inline_form.html" %}
{% load i18n %}
{% block header %}
{% trans "Resend confirmation link" %}
{% endblock %}
{% block form %}
<form name="resend" method="post" action="{% url 'resend-link' %}">
{% csrf_token %}
<div class="field">
<label class="label" for="email">{% trans "Email address:" %}</label>
<div class="control">
<input type="text" name="email" class="input" required id="email">
</div>
</div>
<div class="control">
<button class="button is-link">{% trans "Resend link" %}</button>
</div>
</form>
{% endblock %}

View file

@ -0,0 +1,42 @@
{% extends "components/modal.html" %}
{% load i18n %}
{% block modal-title %}
{% trans "Resend confirmation link" %}
{% endblock %}
{% block modal-form-open %}
<form name="resend" method="post" action="{% url 'resend-link' %}">
{% endblock %}
{% block modal-body %}
{% csrf_token %}
<div class="field">
<label class="label" for="email">{% trans "Email address:" %}</label>
<div class="control">
<input
type="email"
name="email"
class="input"
id="email"
aria-described-by="id_email_errors"
required
>
<div id="id_email_errors">
<p class="help is-danger">
{% trans "No user matching this email address found." %}
</p>
</div>
</div>
</div>
{% endblock %}
{% block modal-footer %}
<div class="control">
<button class="button is-link">{% trans "Resend link" %}</button>
</div>
{% endblock %}
{% block modal-form-close %}
</form>
{% endblock %}

View file

@ -71,7 +71,7 @@ urlpatterns = [
views.ConfirmEmailCode.as_view(), views.ConfirmEmailCode.as_view(),
name="confirm-email-code", 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"^logout/?$", views.Logout.as_view(), name="logout"),
re_path( re_path(
r"^password-reset/?$", r"^password-reset/?$",

View file

@ -52,7 +52,8 @@ from .books.links import BookFileLinks, AddFileLink, delete_link
from .landing.about import about, privacy, conduct from .landing.about import about, privacy, conduct
from .landing.landing import Home, Landing from .landing.landing import Home, Landing
from .landing.login import Login, Logout 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 from .landing.password import PasswordResetRequest, PasswordReset
# shelves # shelves

View file

@ -5,7 +5,6 @@ from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views import View 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 django.views.decorators.debug import sensitive_variables, sensitive_post_parameters
from bookwyrm import emailing, forms, models from bookwyrm import emailing, forms, models
@ -129,11 +128,20 @@ class ConfirmEmail(View):
return ConfirmEmailCode().get(request, code) return ConfirmEmailCode().get(request, code)
@require_POST class ResendConfirmEmail(View):
def resend_link(request): """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""" """resend confirmation link"""
email = request.POST.get("email") email = request.POST.get("email")
user = get_object_or_404(models.User, email=email) try:
user = models.User.objects.get(email=email)
except models.User.DoesNotExist:
return self.get(request, error=True)
emailing.email_confirmation_email(user) emailing.email_confirmation_email(user)
return TemplateResponse( return TemplateResponse(
request, "confirm_email/confirm_email.html", {"valid": True} request, "confirm_email/confirm_email.html", {"valid": True}