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)
|
||||
token = models.CharField(max_length=64, unique=True)
|
||||
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)
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -37,15 +37,21 @@ def handle_status_change(sender, instance, created, **kwargs):
|
|||
headers={"Authorization": f"Bearer {settings.SYNAPSE_ADMIN_TOKEN}"},
|
||||
)
|
||||
|
||||
try:
|
||||
send_mail(
|
||||
"Registration Approved",
|
||||
f"Congratulations, {instance.username}! Your registration at {settings.MATRIX_DOMAIN} has been approved.",
|
||||
settings.DEFAULT_FROM_EMAIL,
|
||||
[instance.email],
|
||||
)
|
||||
except SMTPRecipientsRefused:
|
||||
pass
|
||||
if instance.notify:
|
||||
message = f"Congratulations, your registration request at {settings.MATRIX_DOMAIN} has been approved."
|
||||
|
||||
if instance.mod_message:
|
||||
message += f"\n\nMessage from moderator: {instance.mod_message}"
|
||||
|
||||
try:
|
||||
send_mail(
|
||||
"Registration Approved",
|
||||
message,
|
||||
settings.DEFAULT_FROM_EMAIL,
|
||||
[instance.email],
|
||||
)
|
||||
except SMTPRecipientsRefused:
|
||||
pass
|
||||
|
||||
elif status == UserRegistration.STATUS_DENIED:
|
||||
response = requests.put(
|
||||
|
@ -62,12 +68,18 @@ def handle_status_change(sender, instance, created, **kwargs):
|
|||
[settings.ADMIN_EMAIL],
|
||||
)
|
||||
|
||||
try:
|
||||
send_mail(
|
||||
"Registration Denied",
|
||||
f"Sorry, your registration request at {settings.MATRIX_DOMAIN} has been denied.",
|
||||
settings.DEFAULT_FROM_EMAIL,
|
||||
[instance.email],
|
||||
)
|
||||
except SMTPRecipientsRefused:
|
||||
pass
|
||||
if instance.notify:
|
||||
message = f"Sorry, your registration request at {settings.MATRIX_DOMAIN} has been denied."
|
||||
|
||||
if instance.mod_message:
|
||||
message += f"\n\nMessage from moderator: {instance.mod_message}"
|
||||
|
||||
try:
|
||||
send_mail(
|
||||
"Registration Denied",
|
||||
message,
|
||||
settings.DEFAULT_FROM_EMAIL,
|
||||
[instance.email],
|
||||
)
|
||||
except SMTPRecipientsRefused:
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue