Confirmation templates

This commit is contained in:
Mouse Reeve 2021-08-06 17:23:44 -07:00
parent 5926224d7e
commit 1ad057d89d
6 changed files with 92 additions and 15 deletions

View file

@ -28,7 +28,7 @@ def email_confirmation_email(user):
data = email_data()
data["confirmation_code"] = user.confirmation_code
data["confirmation_link"] = user.confirmation_link
send_email.delay(user.email, *format_email("confirm_email", data))
send_email.delay(user.email, *format_email("confirm", data))
def invite_email(invite_request):

View file

@ -1 +0,0 @@
{% extends "layout.html" %}

View file

@ -0,0 +1,44 @@
{% extends "layout.html" %}
{% load i18n %}
{% block title %}{% trans "Confirm email" %}{% endblock %}
{% block content %}
<h1 class="title">{% trans "Confirm your email address" %}</h1>
<div class="columns">
<div class="column">
<div class="block content">
<section class="block">
<p>{% trans "A confirmation code has been sent to the email address you used to register your account." %}</p>
{% if not valid %}
<p class="notification is-warning">{% trans "Sorry! We couldn't find that code." %}</p>
{% endif %}
<form name="confirm" method="post" action="{% url 'confirm-email' %}">
{% csrf_token %}
<label class="label" for="confirmation_code">{% trans "Confirmation code:" %}</label>
<div class="field has-addons">
<div class="control">
<input class="input" type="text" id="confirmation_code" required>
</div>
<div class="control">
<button class="button is-link" type="submit">{% trans "Submit" %}</button>
</div>
</div>
</form>
</section>
<section class="block">
{% 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" %}
</section>
</div>
</div>
<div class="column">
<div class="box">
{% include 'snippets/about.html' %}
</div>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,19 @@
{% 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' %#}">
<div class="field">
<label class="label" for="email">{% trans "Email address:" %}</label>
<div class="control">
<input type="text" class="input" required id="email">
</div>
</div>
<div class="control">
<button class="button is-link">{% trans "Resend link" %}</button>
</div>
</form>
{% endblock %}

View file

@ -91,6 +91,13 @@
{% trans "Allow invite requests" %}
</label>
</div>
<div class="field">
<label class="label mb-0" for="id_allow_invite_requests">
{{ site_form.require_confirm_email }}
{% trans "Require users to confirm email address" %}
</label>
<p class="help">{% trans "(Recommended if registration is open)" %}</p>
</div>
<div class="field">
<label class="label" for="id_registration_closed_text">{% trans "Registration closed text:" %}</label>
{{ site_form.registration_closed_text }}

View file

@ -144,18 +144,6 @@ class Register(View):
return redirect("get-started-profile")
class ConfirmEmail(View):
"""enter code to confirm email address"""
def get(self, request): # pylint: disable=unused-argument
"""you need a code! keep looking"""
settings = models.SiteSettings.get()
if request.user.is_authenticated or not settings.require_confirm_email:
return redirect("/")
return TemplateResponse(request, "confirm_email.html")
class ConfirmEmailCode(View):
"""confirm email address"""
@ -166,10 +154,30 @@ class ConfirmEmailCode(View):
return redirect("/")
# look up the user associated with this code
user = get_object_or_404(models.User, confirmation_code=code)
try:
user = models.User.objects.get(confirmation_code=code)
except models.User.DoesNotExist:
return TemplateResponse(request, "confirm_email/confirm_email.html", {"valid": False})
# update the user
user.is_active = True
user.deactivation_reason = None
user.save(broadcast=False, update_fields=["is_active", "deactivation_reason"])
# direct the user to log in
return redirect("login", confirmed="confirmed")
class ConfirmEmail(View):
"""enter code to confirm email address"""
def get(self, request): # pylint: disable=unused-argument
"""you need a code! keep looking"""
settings = models.SiteSettings.get()
if request.user.is_authenticated or not settings.require_confirm_email:
return redirect("/")
return TemplateResponse(request, "confirm_email/confirm_email.html", {"valid": True})
def post(self, request):
"""same as clicking the link"""
code = request.POST.get("code")
return ConfirmEmailCode().get(request, code)