diff --git a/config.dist.yaml b/config.dist.yaml index 28079d3..f6f5fc6 100644 --- a/config.dist.yaml +++ b/config.dist.yaml @@ -12,4 +12,6 @@ email: tls: true admin: email: admin@your.server -trust_proxy: false \ No newline at end of file +trust_proxy: false +auto_join: + - "!your_room_id:your.server" diff --git a/src/synapse_registration/registration/signals.py b/src/synapse_registration/registration/signals.py index 8b396ac..c90ffe3 100644 --- a/src/synapse_registration/registration/signals.py +++ b/src/synapse_registration/registration/signals.py @@ -49,6 +49,13 @@ def handle_status_change(sender, instance, created, **kwargs): headers={"Authorization": f"Bearer {settings.SYNAPSE_ADMIN_TOKEN}"}, ) + for room in settings.AUTO_JOIN: + response = requests.post( + f"{settings.SYNAPSE_SERVER}/_synapse/admin/v1/join/{room}", + json={"user_id": f"@{instance.username}:{settings.MATRIX_DOMAIN}"}, + headers={"Authorization": f"Bearer {settings.SYNAPSE_ADMIN_TOKEN}"}, + ) + if response.status_code != 200: send_mail( "Deactivation Failed", diff --git a/src/synapse_registration/registration/views.py b/src/synapse_registration/registration/views.py index bd6d3e5..0aa755f 100644 --- a/src/synapse_registration/registration/views.py +++ b/src/synapse_registration/registration/views.py @@ -144,12 +144,14 @@ class CompleteRegistrationView(FormView): registration.status = UserRegistration.STATUS_REQUESTED registration.registration_reason = registration_reason registration.save() + send_mail( "New Registration Request", f"Approve the new user {username}", settings.DEFAULT_FROM_EMAIL, [settings.ADMIN_EMAIL], ) + return render(self.request, "registration/registration_pending.html") form.add_error(None, "Registration failed.") diff --git a/src/synapse_registration/synapse_registration/settings.py b/src/synapse_registration/synapse_registration/settings.py index 856f71a..4ae0ee6 100644 --- a/src/synapse_registration/synapse_registration/settings.py +++ b/src/synapse_registration/synapse_registration/settings.py @@ -69,6 +69,11 @@ SYNAPSE_SERVER = config["synapse"]["server"] SYNAPSE_ADMIN_TOKEN = config["synapse"]["admin_token"] MATRIX_DOMAIN = config["synapse"]["domain"] +if "auto_join" in config: + AUTO_JOIN = config["auto_join"] +else: + AUTO_JOIN = [] + response = requests.get( f"{SYNAPSE_SERVER}/_matrix/client/r0/account/whoami", headers={"Authorization": f"Bearer {SYNAPSE_ADMIN_TOKEN}"},