-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[1/2] Allow homeservers to send registration emails | Sending the email #5835
Changes from all commits
eacd505
959c051
0197954
c7a2317
053638d
176dd5d
73df394
c092a35
616ee20
994c51f
cc5983d
4f035bd
c8ba612
7f402b1
858414f
7e983f9
7cd1133
6b053d3
a6e22d7
a03cc2a
075541a
9e1e774
798e72b
1bc713d
70127b8
03d3789
75b279e
53c5432
f14b097
6706844
b29c62b
9b1a340
ace8fa5
5113d9e
06815e8
4dd5b97
80abdf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add the ability to send registration emails from the homeserver rather than delegating to an identity server. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ def read_config(self, config, **kwargs): | |
"renew_at" | ||
) | ||
|
||
self.email_threepid_behaviour = ( | ||
self.threepid_behaviour = ( | ||
# Have Synapse handle the email sending if account_threepid_delegate | ||
# is not defined | ||
ThreepidBehaviour.REMOTE | ||
|
@@ -87,9 +87,14 @@ def read_config(self, config, **kwargs): | |
# if they have this set and tell them to use the updated option, while using a default | ||
# identity server in the process. | ||
self.using_identity_server_from_trusted_list = False | ||
if config.get("trust_identity_server_for_password_resets", False) is True: | ||
if ( | ||
not self.account_threepid_delegate | ||
and config.get("trust_identity_server_for_password_resets", False) is True | ||
): | ||
# Use the first entry in self.trusted_third_party_id_servers instead | ||
if self.trusted_third_party_id_servers: | ||
# XXX: It's a little confusing that account_threepid_delegate is modifed | ||
# both in RegistrationConfig and here. We should factor this bit out | ||
self.account_threepid_delegate = self.trusted_third_party_id_servers[0] | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.using_identity_server_from_trusted_list = True | ||
else: | ||
|
@@ -98,16 +103,13 @@ def read_config(self, config, **kwargs): | |
'"trusted_third_party_id_servers" but it is empty.' | ||
) | ||
|
||
self.local_threepid_emails_disabled_due_to_config = False | ||
if ( | ||
self.email_threepid_behaviour == ThreepidBehaviour.LOCAL | ||
and email_config == {} | ||
): | ||
self.local_threepid_handling_disabled_due_to_email_config = False | ||
if self.threepid_behaviour == ThreepidBehaviour.LOCAL and email_config == {}: | ||
# We cannot warn the user this has happened here | ||
# Instead do so when a user attempts to reset their password | ||
self.local_threepid_emails_disabled_due_to_config = True | ||
self.local_threepid_handling_disabled_due_to_email_config = True | ||
|
||
self.email_threepid_behaviour = ThreepidBehaviour.OFF | ||
self.threepid_behaviour = ThreepidBehaviour.OFF | ||
|
||
# Get lifetime of a validation token in milliseconds | ||
self.email_validation_token_lifetime = self.parse_duration( | ||
|
@@ -117,7 +119,7 @@ def read_config(self, config, **kwargs): | |
if ( | ||
self.email_enable_notifs | ||
or account_validity_renewal_enabled | ||
or self.email_threepid_behaviour == ThreepidBehaviour.LOCAL | ||
or self.threepid_behaviour == ThreepidBehaviour.LOCAL | ||
): | ||
# make sure we can import the required deps | ||
import jinja2 | ||
|
@@ -127,7 +129,7 @@ def read_config(self, config, **kwargs): | |
jinja2 | ||
bleach | ||
|
||
if self.email_threepid_behaviour == ThreepidBehaviour.LOCAL: | ||
if self.threepid_behaviour == ThreepidBehaviour.LOCAL: | ||
required = ["smtp_host", "smtp_port", "notif_from"] | ||
|
||
missing = [] | ||
|
@@ -146,28 +148,45 @@ def read_config(self, config, **kwargs): | |
% (", ".join(missing),) | ||
) | ||
|
||
# Templates for password reset emails | ||
# These email templates have placeholders in them, and thus must be | ||
# parsed using a templating engine during a request | ||
self.email_password_reset_template_html = email_config.get( | ||
"password_reset_template_html", "password_reset.html" | ||
) | ||
self.email_password_reset_template_text = email_config.get( | ||
"password_reset_template_text", "password_reset.txt" | ||
) | ||
self.email_registration_template_html = email_config.get( | ||
"registration_template_html", "registration.html" | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
self.email_registration_template_text = email_config.get( | ||
"registration_template_text", "registration.txt" | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
self.email_password_reset_template_failure_html = email_config.get( | ||
"password_reset_template_failure_html", "password_reset_failure.html" | ||
) | ||
# This template does not support any replaceable variables, so we will | ||
# read it from the disk once during setup | ||
self.email_registration_template_failure_html = email_config.get( | ||
"registration_template_failure_html", "registration_failure.html" | ||
) | ||
|
||
# These templates do not support any placeholder variables, so we | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm kinda wondering if a better solution is to remove the special-casing and stick them through the template engine anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be more clear, but we'd have to pull the template from the disk every time we get a registration request. So a question of code quality versus performance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given we have to do that anyway for the other templates, it feels like a hit worth taking. But also, maybe something to think about another time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll punt it for later. |
||
# will read them from disk once during setup | ||
email_password_reset_template_success_html = email_config.get( | ||
"password_reset_template_success_html", "password_reset_success.html" | ||
) | ||
email_registration_template_success_html = email_config.get( | ||
"registration_template_success_html", "registration_success.html" | ||
) | ||
|
||
# Check templates exist | ||
for f in [ | ||
self.email_password_reset_template_html, | ||
self.email_password_reset_template_text, | ||
self.email_registration_template_html, | ||
self.email_registration_template_text, | ||
self.email_password_reset_template_failure_html, | ||
email_password_reset_template_success_html, | ||
email_registration_template_success_html, | ||
]: | ||
p = os.path.join(self.email_template_dir, f) | ||
if not os.path.isfile(p): | ||
|
@@ -177,9 +196,15 @@ def read_config(self, config, **kwargs): | |
filepath = os.path.join( | ||
self.email_template_dir, email_password_reset_template_success_html | ||
) | ||
self.email_password_reset_template_success_html_content = self.read_file( | ||
self.email_password_reset_template_success_html = self.read_file( | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
filepath, "email.password_reset_template_success_html" | ||
) | ||
filepath = os.path.join( | ||
self.email_template_dir, email_registration_template_success_html | ||
) | ||
self.email_registration_template_success_html_content = self.read_file( | ||
filepath, "email.registration_template_success_html" | ||
) | ||
|
||
if self.email_enable_notifs: | ||
required = [ | ||
|
@@ -291,11 +316,22 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs): | |
# #password_reset_template_html: password_reset.html | ||
# #password_reset_template_text: password_reset.txt | ||
# | ||
# # Templates for registration emails sent by the homeserver | ||
# # | ||
# #registration_template_html: registration.html | ||
# #registration_template_text: registration.txt | ||
# | ||
# # Templates for password reset success and failure pages that a user | ||
# # will see after attempting to reset their password | ||
# # | ||
# #password_reset_template_success_html: password_reset_success.html | ||
# #password_reset_template_failure_html: password_reset_failure.html | ||
# | ||
# # Templates for registration success and failure pages that a user | ||
# # will see after attempting to register using an email or phone | ||
# # | ||
# #registration_template_success_html: registration_success.html | ||
# #registration_template_failure_html: registration_failure.html | ||
""" | ||
|
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.