forked from mirrors/bookwyrm
Fixes sending invite emails
Corrects the email sender and avoids integrity error on saves
This commit is contained in:
parent
fd97b167e1
commit
f63b6fb325
4 changed files with 9 additions and 6 deletions
|
@ -2,7 +2,7 @@
|
|||
from django.core.mail import EmailMultiAlternatives
|
||||
from django.template.loader import get_template
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm import models, settings
|
||||
from bookwyrm.tasks import app
|
||||
from bookwyrm.settings import DOMAIN
|
||||
|
||||
|
@ -59,6 +59,8 @@ def format_email(email_name, data):
|
|||
@app.task
|
||||
def send_email(recipient, subject, html_content, text_content):
|
||||
""" 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.send()
|
||||
|
|
|
@ -83,7 +83,7 @@ class InviteRequest(BookWyrmModel):
|
|||
|
||||
def save(self, *args, **kwargs):
|
||||
""" 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()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ EMAIL_PORT = env("EMAIL_PORT", 587)
|
|||
EMAIL_HOST_USER = env("EMAIL_HOST_USER")
|
||||
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
|
||||
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, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
{% trans 'Settings' %}
|
||||
</a>
|
||||
</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>
|
||||
{% endif %}
|
||||
{% if perms.bookwyrm.create_invites %}
|
||||
|
@ -117,9 +117,9 @@
|
|||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if perms.bookwyrm.edit_instance_settings %}
|
||||
{% if perms.bookwyrm.moderate_users %}
|
||||
<li>
|
||||
<a href="{% url 'settings-reports' %}" class="navbar-item">
|
||||
<a href="{% url 'settings-users' %}" class="navbar-item">
|
||||
{% trans 'Admin' %}
|
||||
</a>
|
||||
</li>
|
||||
|
|
Loading…
Reference in a new issue