Merge pull request #817 from mouse-reeve/invite-emails

Fixes sending invite emails
This commit is contained in:
Mouse Reeve 2021-03-29 09:09:19 -07:00 committed by GitHub
commit 87cf411a1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 6 deletions

View file

@ -2,7 +2,7 @@
from django.core.mail import EmailMultiAlternatives from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template from django.template.loader import get_template
from bookwyrm import models from bookwyrm import models, settings
from bookwyrm.tasks import app from bookwyrm.tasks import app
from bookwyrm.settings import DOMAIN from bookwyrm.settings import DOMAIN
@ -59,6 +59,8 @@ def format_email(email_name, data):
@app.task @app.task
def send_email(recipient, subject, html_content, text_content): def send_email(recipient, subject, html_content, text_content):
""" use a task to send the email """ """ use a task to send the email """
email = EmailMultiAlternatives(subject, text_content, None, [recipient]) email = EmailMultiAlternatives(
subject, text_content, settings.DEFAULT_FROM_EMAIL, [recipient]
)
email.attach_alternative(html_content, "text/html") email.attach_alternative(html_content, "text/html")
email.send() email.send()

View file

@ -83,7 +83,7 @@ class InviteRequest(BookWyrmModel):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
""" don't create a request for a registered email """ """ don't create a request for a registered email """
if User.objects.filter(email=self.email).exists(): if not self.id and User.objects.filter(email=self.email).exists():
raise IntegrityError() raise IntegrityError()
super().save(*args, **kwargs) super().save(*args, **kwargs)

View file

@ -25,6 +25,7 @@ EMAIL_PORT = env("EMAIL_PORT", 587)
EMAIL_HOST_USER = env("EMAIL_HOST_USER") EMAIL_HOST_USER = env("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD") EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
EMAIL_USE_TLS = env("EMAIL_USE_TLS", True) EMAIL_USE_TLS = env("EMAIL_USE_TLS", True)
DEFAULT_FROM_EMAIL = "admin@{:s}".format(env("DOMAIN"))
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

View file

@ -107,7 +107,7 @@
{% trans 'Settings' %} {% trans 'Settings' %}
</a> </a>
</li> </li>
{% if perms.bookwyrm.create_invites or perms.bookwyrm.edit_instance_settings%} {% if perms.bookwyrm.create_invites or perms.moderate_users %}
<li class="navbar-divider" role="presentation"></li> <li class="navbar-divider" role="presentation"></li>
{% endif %} {% endif %}
{% if perms.bookwyrm.create_invites %} {% if perms.bookwyrm.create_invites %}
@ -117,9 +117,9 @@
</a> </a>
</li> </li>
{% endif %} {% endif %}
{% if perms.bookwyrm.edit_instance_settings %} {% if perms.bookwyrm.moderate_users %}
<li> <li>
<a href="{% url 'settings-reports' %}" class="navbar-item"> <a href="{% url 'settings-users' %}" class="navbar-item">
{% trans 'Admin' %} {% trans 'Admin' %}
</a> </a>
</li> </li>