forked from mirrors/bookwyrm
Resend links
This commit is contained in:
parent
1ad057d89d
commit
9077516fa1
6 changed files with 31 additions and 6 deletions
|
@ -19,7 +19,7 @@
|
||||||
<label class="label" for="confirmation_code">{% trans "Confirmation code:" %}</label>
|
<label class="label" for="confirmation_code">{% trans "Confirmation code:" %}</label>
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="text" id="confirmation_code" required>
|
<input class="input" type="text" name="code" id="confirmation_code" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<button class="button is-link" type="submit">{% trans "Submit" %}</button>
|
<button class="button is-link" type="submit">{% trans "Submit" %}</button>
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block form %}
|
{% block form %}
|
||||||
<form name="resend" method="post" action="{#% url 'resend-link' %#}">
|
<form name="resend" method="post" action="{% url 'resend-link' %}">
|
||||||
|
{% csrf_token %}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label" for="email">{% trans "Email address:" %}</label>
|
<label class="label" for="email">{% trans "Email address:" %}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input type="text" class="input" required id="email">
|
<input type="text" name="email" class="input" required id="email">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
|
|
@ -11,8 +11,13 @@
|
||||||
{% if login_form.non_field_errors %}
|
{% if login_form.non_field_errors %}
|
||||||
<p class="notification is-danger">{{ login_form.non_field_errors }}</p>
|
<p class="notification is-danger">{{ login_form.non_field_errors }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if show_confirmed_email %}
|
||||||
|
<p class="notification is-success">{% trans "Success! Email address confirmed." %}</p>
|
||||||
|
{% endif %}
|
||||||
<form name="login" method="post" action="/login">
|
<form name="login" method="post" action="/login">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
{% if show_confirmed_email %}<input type="hidden" name="first_login" value="true">{% endif %}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label" for="id_localname">{% trans "Username:" %}</label>
|
<label class="label" for="id_localname">{% trans "Username:" %}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
|
|
@ -54,6 +54,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"^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/?$",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
""" make sure all our nice views are available """
|
""" make sure all our nice views are available """
|
||||||
from .announcements import Announcements, Announcement, delete_announcement
|
from .announcements import Announcements, Announcement, delete_announcement
|
||||||
from .authentication import Login, Register, Logout
|
from .authentication import Login, Register, Logout
|
||||||
from .authentication import ConfirmEmail, ConfirmEmailCode
|
from .authentication import ConfirmEmail, ConfirmEmailCode, resend_link
|
||||||
from .author import Author, EditAuthor
|
from .author import Author, EditAuthor
|
||||||
from .block import Block, unblock
|
from .block import Block, unblock
|
||||||
from .books import Book, EditBook, ConfirmEditBook, Editions
|
from .books import Book, EditBook, ConfirmEditBook, Editions
|
||||||
|
|
|
@ -7,6 +7,7 @@ from django.template.response import TemplateResponse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from django.views.decorators.http import require_POST
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import emailing, forms, models
|
from bookwyrm import emailing, forms, models
|
||||||
|
@ -53,6 +54,8 @@ class Login(View):
|
||||||
login(request, user)
|
login(request, user)
|
||||||
user.last_active_date = timezone.now()
|
user.last_active_date = timezone.now()
|
||||||
user.save(broadcast=False, update_fields=["last_active_date"])
|
user.save(broadcast=False, update_fields=["last_active_date"])
|
||||||
|
if request.POST.get("first_login"):
|
||||||
|
return redirect("get-started-profile")
|
||||||
return redirect(request.GET.get("next", "/"))
|
return redirect(request.GET.get("next", "/"))
|
||||||
|
|
||||||
# maybe the user is pending email confirmation
|
# maybe the user is pending email confirmation
|
||||||
|
@ -157,7 +160,9 @@ class ConfirmEmailCode(View):
|
||||||
try:
|
try:
|
||||||
user = models.User.objects.get(confirmation_code=code)
|
user = models.User.objects.get(confirmation_code=code)
|
||||||
except models.User.DoesNotExist:
|
except models.User.DoesNotExist:
|
||||||
return TemplateResponse(request, "confirm_email/confirm_email.html", {"valid": False})
|
return TemplateResponse(
|
||||||
|
request, "confirm_email/confirm_email.html", {"valid": False}
|
||||||
|
)
|
||||||
# update the user
|
# update the user
|
||||||
user.is_active = True
|
user.is_active = True
|
||||||
user.deactivation_reason = None
|
user.deactivation_reason = None
|
||||||
|
@ -175,9 +180,22 @@ class ConfirmEmail(View):
|
||||||
if request.user.is_authenticated or not settings.require_confirm_email:
|
if request.user.is_authenticated or not settings.require_confirm_email:
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
return TemplateResponse(request, "confirm_email/confirm_email.html", {"valid": True})
|
return TemplateResponse(
|
||||||
|
request, "confirm_email/confirm_email.html", {"valid": True}
|
||||||
|
)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
"""same as clicking the link"""
|
"""same as clicking the link"""
|
||||||
code = request.POST.get("code")
|
code = request.POST.get("code")
|
||||||
return ConfirmEmailCode().get(request, code)
|
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}
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue