Send notification on new user creations
This commit is contained in:
parent
8de99c1bcd
commit
50820172b1
|
@ -8,7 +8,9 @@ log = logs.get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# Actual function to send a message to a topic
|
# Actual function to send a message to a topic
|
||||||
def _sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None):
|
def raw_sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None):
|
||||||
|
if url is None:
|
||||||
|
url = NTFY_URL
|
||||||
headers = {"Title": "Fisk"}
|
headers = {"Title": "Fisk"}
|
||||||
if title:
|
if title:
|
||||||
headers["Title"] = title
|
headers["Title"] = title
|
||||||
|
@ -26,10 +28,6 @@ def _sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None):
|
||||||
# Sendmsg helper to send a message to a user's notification settings
|
# Sendmsg helper to send a message to a user's notification settings
|
||||||
def sendmsg(user, *args, **kwargs):
|
def sendmsg(user, *args, **kwargs):
|
||||||
notification_settings = user.get_notification_settings()
|
notification_settings = user.get_notification_settings()
|
||||||
if notification_settings.ntfy_url is None:
|
|
||||||
url = NTFY_URL
|
|
||||||
else:
|
|
||||||
url = notification_settings.ntfy_url
|
|
||||||
|
|
||||||
if notification_settings.ntfy_topic is None:
|
if notification_settings.ntfy_topic is None:
|
||||||
# No topic set, so don't send
|
# No topic set, so don't send
|
||||||
|
@ -37,4 +35,4 @@ def sendmsg(user, *args, **kwargs):
|
||||||
else:
|
else:
|
||||||
topic = notification_settings.ntfy_topic
|
topic = notification_settings.ntfy_topic
|
||||||
|
|
||||||
_sendmsg(*args, **kwargs, url=url, topic=topic)
|
raw_sendmsg(*args, **kwargs, url=notification_settings.ntfy_url, topic=topic)
|
||||||
|
|
|
@ -11,6 +11,7 @@ from django.views import View
|
||||||
from django.views.generic.edit import CreateView
|
from django.views.generic.edit import CreateView
|
||||||
|
|
||||||
from core.forms import NewUserForm
|
from core.forms import NewUserForm
|
||||||
|
from core.lib.notify import raw_sendmsg
|
||||||
from core.lib.products import assemble_plan_map
|
from core.lib.products import assemble_plan_map
|
||||||
from core.models import Plan, Session
|
from core.models import Plan, Session
|
||||||
|
|
||||||
|
@ -91,6 +92,16 @@ class Signup(CreateView):
|
||||||
success_url = reverse_lazy("two_factor:login")
|
success_url = reverse_lazy("two_factor:login")
|
||||||
template_name = "registration/signup.html"
|
template_name = "registration/signup.html"
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
"""If the form is valid, save the associated model."""
|
||||||
|
self.object = form.save()
|
||||||
|
raw_sendmsg(
|
||||||
|
f"New user signup: {self.object.username} - {self.object.email}",
|
||||||
|
title="New user",
|
||||||
|
topic=settings.NOTIFY_TOPIC,
|
||||||
|
)
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if not settings.REGISTRATION_OPEN:
|
if not settings.REGISTRATION_OPEN:
|
||||||
return render(request, "registration/registration_closed.html")
|
return render(request, "registration/registration_closed.html")
|
||||||
|
|
Loading…
Reference in New Issue