feat: Enhances registration notifications
Adds moderator messages to registration emails. Introduces 'notify' flag to control email notifications. Improves customization of user communication during status updates.
This commit is contained in:
parent
9a94f4b905
commit
7de4a3f2c5
2 changed files with 32 additions and 18 deletions
|
@ -23,6 +23,8 @@ class UserRegistration(models.Model):
|
||||||
status = models.IntegerField(choices=STATUS_CHOICES, default=STATUS_STARTED)
|
status = models.IntegerField(choices=STATUS_CHOICES, default=STATUS_STARTED)
|
||||||
token = models.CharField(max_length=64, unique=True)
|
token = models.CharField(max_length=64, unique=True)
|
||||||
email_verified = models.BooleanField(default=False)
|
email_verified = models.BooleanField(default=False)
|
||||||
|
mod_message = models.TextField(blank=True, default="")
|
||||||
|
notify = models.BooleanField(default=True)
|
||||||
timestamp = models.DateTimeField(auto_now_add=True)
|
timestamp = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -37,15 +37,21 @@ def handle_status_change(sender, instance, created, **kwargs):
|
||||||
headers={"Authorization": f"Bearer {settings.SYNAPSE_ADMIN_TOKEN}"},
|
headers={"Authorization": f"Bearer {settings.SYNAPSE_ADMIN_TOKEN}"},
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
if instance.notify:
|
||||||
send_mail(
|
message = f"Congratulations, your registration request at {settings.MATRIX_DOMAIN} has been approved."
|
||||||
"Registration Approved",
|
|
||||||
f"Congratulations, {instance.username}! Your registration at {settings.MATRIX_DOMAIN} has been approved.",
|
if instance.mod_message:
|
||||||
settings.DEFAULT_FROM_EMAIL,
|
message += f"\n\nMessage from moderator: {instance.mod_message}"
|
||||||
[instance.email],
|
|
||||||
)
|
try:
|
||||||
except SMTPRecipientsRefused:
|
send_mail(
|
||||||
pass
|
"Registration Approved",
|
||||||
|
message,
|
||||||
|
settings.DEFAULT_FROM_EMAIL,
|
||||||
|
[instance.email],
|
||||||
|
)
|
||||||
|
except SMTPRecipientsRefused:
|
||||||
|
pass
|
||||||
|
|
||||||
elif status == UserRegistration.STATUS_DENIED:
|
elif status == UserRegistration.STATUS_DENIED:
|
||||||
response = requests.put(
|
response = requests.put(
|
||||||
|
@ -62,12 +68,18 @@ def handle_status_change(sender, instance, created, **kwargs):
|
||||||
[settings.ADMIN_EMAIL],
|
[settings.ADMIN_EMAIL],
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
if instance.notify:
|
||||||
send_mail(
|
message = f"Sorry, your registration request at {settings.MATRIX_DOMAIN} has been denied."
|
||||||
"Registration Denied",
|
|
||||||
f"Sorry, your registration request at {settings.MATRIX_DOMAIN} has been denied.",
|
if instance.mod_message:
|
||||||
settings.DEFAULT_FROM_EMAIL,
|
message += f"\n\nMessage from moderator: {instance.mod_message}"
|
||||||
[instance.email],
|
|
||||||
)
|
try:
|
||||||
except SMTPRecipientsRefused:
|
send_mail(
|
||||||
pass
|
"Registration Denied",
|
||||||
|
message,
|
||||||
|
settings.DEFAULT_FROM_EMAIL,
|
||||||
|
[instance.email],
|
||||||
|
)
|
||||||
|
except SMTPRecipientsRefused:
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in a new issue