mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
Email confirmation email
This commit is contained in:
parent
3e2f1806e9
commit
247a7f7489
10 changed files with 72 additions and 6 deletions
|
@ -36,6 +36,9 @@ FLOWER_PORT=8888
|
|||
#FLOWER_USER=mouse
|
||||
#FLOWER_PASSWORD=changeme
|
||||
|
||||
# make users confirm their email addresses after registration
|
||||
CONFIRM_EMAIL=false
|
||||
|
||||
EMAIL_HOST="smtp.mailgun.org"
|
||||
EMAIL_PORT=587
|
||||
EMAIL_HOST_USER=mail@your.domain.here
|
||||
|
|
|
@ -36,6 +36,9 @@ FLOWER_PORT=8888
|
|||
FLOWER_USER=mouse
|
||||
FLOWER_PASSWORD=changeme
|
||||
|
||||
# make users confirm their email addresses after registration
|
||||
CONFIRM_EMAIL=true
|
||||
|
||||
EMAIL_HOST="smtp.mailgun.org"
|
||||
EMAIL_PORT=587
|
||||
EMAIL_HOST_USER=mail@your.domain.here
|
||||
|
|
|
@ -23,6 +23,13 @@ def email_data():
|
|||
}
|
||||
|
||||
|
||||
def email_confirmation_email(user):
|
||||
"""newly registered users confirm email address"""
|
||||
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))
|
||||
|
||||
def invite_email(invite_request):
|
||||
"""send out an invite code"""
|
||||
data = email_data()
|
||||
|
|
|
@ -17,7 +17,7 @@ from bookwyrm.connectors import get_data, ConnectorException
|
|||
from bookwyrm.models.shelf import Shelf
|
||||
from bookwyrm.models.status import Status, Review
|
||||
from bookwyrm.preview_images import generate_user_preview_image_task
|
||||
from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES
|
||||
from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES, USE_HTTPS
|
||||
from bookwyrm.signatures import create_key_pair
|
||||
from bookwyrm.tasks import app
|
||||
from bookwyrm.utils import regex
|
||||
|
@ -26,6 +26,10 @@ from .base_model import BookWyrmModel, DeactivationReason, new_access_code
|
|||
from .federated_server import FederatedServer
|
||||
from . import fields, Review
|
||||
|
||||
def site_link():
|
||||
"""helper for generating links to the site"""
|
||||
protocol = "https" if USE_HTTPS else "http"
|
||||
return f"{protocol}://{DOMAIN}"
|
||||
|
||||
class User(OrderedCollectionPageMixin, AbstractUser):
|
||||
"""a user who wants to read books"""
|
||||
|
@ -129,6 +133,12 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||
property_fields = [("following_link", "following")]
|
||||
field_tracker = FieldTracker(fields=["name", "avatar"])
|
||||
|
||||
@property
|
||||
def confirmation_link(self):
|
||||
"""helper for generating confirmation links"""
|
||||
link = site_link()
|
||||
return f"{link}/confirm-email/{self.confirmation_code}"
|
||||
|
||||
@property
|
||||
def following_link(self):
|
||||
"""just how to find out the following info"""
|
||||
|
@ -260,9 +270,9 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||
return
|
||||
|
||||
# populate fields for local users
|
||||
self.remote_id = "https://%s/user/%s" % (DOMAIN, self.localname)
|
||||
self.remote_id = "%s/user/%s" % (site_link(), self.localname)
|
||||
self.inbox = "%s/inbox" % self.remote_id
|
||||
self.shared_inbox = "https://%s/inbox" % DOMAIN
|
||||
self.shared_inbox = "%s/inbox" % site_link()
|
||||
self.outbox = "%s/outbox" % self.remote_id
|
||||
|
||||
# an id needs to be set before we can proceed with related models
|
||||
|
|
|
@ -24,6 +24,9 @@ CELERY_ACCEPT_CONTENT = ["application/json"]
|
|||
CELERY_TASK_SERIALIZER = "json"
|
||||
CELERY_RESULT_SERIALIZER = "json"
|
||||
|
||||
# make users confirm their email addresses after registration
|
||||
CONFIRM_EMAIL = env("CONFIRM_EMAIL", True)
|
||||
|
||||
# email
|
||||
EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend")
|
||||
EMAIL_HOST = env("EMAIL_HOST")
|
||||
|
|
14
bookwyrm/templates/email/confirm/html_content.html
Normal file
14
bookwyrm/templates/email/confirm/html_content.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends 'email/html_layout.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
{% blocktrans trimmed %}
|
||||
One last step before you join {{ site_name }}! Please confirm your email address by clicking the link below:
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
|
||||
{% trans "Confirm Email" as text %}
|
||||
{% include 'email/snippets/action.html' with path=confirmation_link text=text %}
|
||||
|
||||
{% endblock %}
|
4
bookwyrm/templates/email/confirm/subject.html
Normal file
4
bookwyrm/templates/email/confirm/subject.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{% load i18n %}
|
||||
{% blocktrans trimmed %}
|
||||
Please confirm your email
|
||||
{% endblocktrans %}
|
11
bookwyrm/templates/email/confirm/text_content.html
Normal file
11
bookwyrm/templates/email/confirm/text_content.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% extends 'email/text_layout.html' %}
|
||||
{% load i18n %}
|
||||
{% block content %}
|
||||
{% blocktrans trimmed %}
|
||||
One last step before you join {{ site_name }}! Please confirm your email address by clicking the link below:
|
||||
{% endblocktrans %}
|
||||
|
||||
{{ confirmation_link }}
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -9,8 +9,8 @@ from django.utils.decorators import method_decorator
|
|||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views import View
|
||||
|
||||
from bookwyrm import forms, models
|
||||
from bookwyrm.settings import DOMAIN
|
||||
from bookwyrm import emailing, forms, models
|
||||
from bookwyrm.settings import DOMAIN, CONFIRM_EMAIL
|
||||
|
||||
|
||||
# pylint: disable= no-self-use
|
||||
|
@ -104,13 +104,22 @@ class Register(View):
|
|||
|
||||
username = "%s@%s" % (localname, DOMAIN)
|
||||
user = models.User.objects.create_user(
|
||||
username, email, password, localname=localname, local=True
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
localname=localname,
|
||||
local=True,
|
||||
is_active=not CONFIRM_EMAIL,
|
||||
)
|
||||
if invite:
|
||||
invite.times_used += 1
|
||||
invite.invitees.add(user)
|
||||
invite.save()
|
||||
|
||||
if CONFIRM_EMAIL:
|
||||
emailing.email_confirmation_email(user)
|
||||
return redirect("confirm-email")
|
||||
|
||||
login(request, user)
|
||||
return redirect("get-started-profile")
|
||||
|
||||
|
|
|
@ -46,4 +46,6 @@ def email_preview(request):
|
|||
data["text_content_path"] = "email/{}/text_content.html".format(template)
|
||||
data["reset_link"] = "https://example.com/link"
|
||||
data["invite_link"] = "https://example.com/link"
|
||||
data["confirmation_link"] = "https://example.com/link"
|
||||
data["confirmation_code"] = "AKJHKDGKJSDFG"
|
||||
return TemplateResponse(request, "email/preview.html", data)
|
||||
|
|
Loading…
Reference in a new issue