Get first signup email through
This commit is contained in:
+8
-17
@@ -7,9 +7,6 @@ from django.utils.translation import ugettext as _
|
|||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
import logging
|
|
||||||
from smtplib import SMTPAuthenticationError
|
|
||||||
|
|
||||||
from members.models import Member, Request
|
from members.models import Member, Request
|
||||||
from webapp.utils import send_email
|
from webapp.utils import send_email
|
||||||
|
|
||||||
@@ -20,13 +17,10 @@ def email_on_request(sender, instance, created, **kwargs):
|
|||||||
if not settings.ENABLE_AUTOMATIC_EMAILS:
|
if not settings.ENABLE_AUTOMATIC_EMAILS:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
if created:
|
||||||
if created:
|
subject = 'Test1'
|
||||||
subject = 'Test1'
|
message = 'Please validate your email address\r\n'
|
||||||
message = 'Please validate your email address\r\n'
|
send_email(instance.email, subject, message)
|
||||||
send_email(instance.email, subject, message)
|
|
||||||
except SMTPAuthenticationError:
|
|
||||||
logging.error('Failed to send email to accepted request!')
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Member)
|
@receiver(post_save, sender=Member)
|
||||||
@@ -35,10 +29,7 @@ def email_on_accept(sender, instance, created, **kwargs):
|
|||||||
if not settings.ENABLE_AUTOMATIC_EMAILS:
|
if not settings.ENABLE_AUTOMATIC_EMAILS:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
if created:
|
||||||
if created:
|
subject = 'Test2'
|
||||||
subject = 'Test2'
|
message = 'Jäsenhakemuksesi on hyväksytty!!!\r\n'
|
||||||
message = 'Jäsenhakemuksesi on hyväksytty!!!\r\n'
|
send_email(instance.email, subject, message)
|
||||||
send_email(instance.email, subject, message)
|
|
||||||
except SMTPAuthenticationError:
|
|
||||||
logging.error('Failed to send email to accepted member!')
|
|
||||||
|
|||||||
+11
-10
@@ -14,7 +14,6 @@ from phonenumber_field.modelfields import PhoneNumberField
|
|||||||
from django.contrib.postgres.fields import JSONField
|
from django.contrib.postgres.fields import JSONField
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import logging
|
import logging
|
||||||
from smtplib import SMTPAuthenticationError
|
|
||||||
|
|
||||||
VERBOSE_NAME = _('Webapp')
|
VERBOSE_NAME = _('Webapp')
|
||||||
EMAIL_REGEX = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
|
EMAIL_REGEX = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
|
||||||
@@ -186,18 +185,20 @@ class Signup(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Signup)
|
@receiver(post_save, sender=Signup)
|
||||||
def email_on_singup(sender, instance, created, **kwargs):
|
def email_on_signup(sender, instance, created, **kwargs):
|
||||||
"""Send email validation."""
|
"""Send email validation."""
|
||||||
if not settings.ENABLE_AUTOMATIC_EMAILS:
|
if not settings.ENABLE_AUTOMATIC_EMAILS:
|
||||||
return
|
return
|
||||||
|
if created and instance.email:
|
||||||
try:
|
# TODO: Possible bug due to many-to-many relationship with events and forms.
|
||||||
if created and instance.email:
|
# TODO: Subject field crashes with lazy loaded translations.
|
||||||
# TODO: Possible bug due to many-to-many relationship with events and forms.
|
try:
|
||||||
subject = _(f"Olet ilmoittautunut tapahtumaan {instance.signupForm.event.first().title}")
|
# subject = _(f"Olet ilmoittautunut tapahtumaan {instance.signupForm.event.first().title}")
|
||||||
send_signup_email(instance.email, subject, instance.id, instance.uuid)
|
subject = f"Olet ilmoittautunut tapahtumaan {instance.signupForm.event.first().title}"
|
||||||
except SMTPAuthenticationError:
|
except AttributeError:
|
||||||
logging.error('Failed to send email to signup')
|
# subject = _(f"Olet ilmoittautunut ilmoon {instance.signupForm.title}")
|
||||||
|
subject = f"Olet ilmoittautunut ilmoon {instance.signupForm.title}"
|
||||||
|
send_signup_email(instance.email, subject, instance.id, instance.uuid)
|
||||||
|
|
||||||
|
|
||||||
class BaseRole(models.Model):
|
class BaseRole(models.Model):
|
||||||
|
|||||||
+2
-3
@@ -42,13 +42,12 @@ def send_email(to, subject, body, fail_silently=False):
|
|||||||
}
|
}
|
||||||
success = mailjet.send.create(data=data)
|
success = mailjet.send.create(data=data)
|
||||||
|
|
||||||
if success.status_code != 201:
|
# For some reason returns 200 OK instead of 201 Created...
|
||||||
|
if success.status_code != 200:
|
||||||
raise Exception(f'Failed to send email: {success.json()}')
|
raise Exception(f'Failed to send email: {success.json()}')
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.exception('Failed to send email.')
|
logging.exception('Failed to send email.')
|
||||||
logging.debug(EMAIL_API_KEY)
|
|
||||||
logging.debug(EMAIL_API_SECRET)
|
|
||||||
|
|
||||||
|
|
||||||
def send_signup_email(to, subject, id, uuid):
|
def send_signup_email(to, subject, id, uuid):
|
||||||
|
|||||||
Reference in New Issue
Block a user