-
-
Couldn't load subscription status.
- Fork 2.1k
[1/2] Allow homeservers to send registration emails | Sending the email #5835
Changes from 10 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 @@ | ||
| Ability to send registration emails from the homeserver. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,19 +74,20 @@ def read_config(self, config, **kwargs): | |
| "renew_at" | ||
| ) | ||
|
|
||
| email_trust_identity_server_for_password_resets = email_config.get( | ||
| "trust_identity_server_for_password_resets", False | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.email_threepid_behaviour = ( | ||
| # Have Synapse handle the email sending if account_threepid_delegate | ||
| # is not defined | ||
| "remote" | ||
| if self.account_threepid_delegate | ||
| else "local" | ||
| ) | ||
| self.email_password_reset_behaviour = ( | ||
| "remote" if email_trust_identity_server_for_password_resets else "local" | ||
| ) | ||
| self.password_resets_were_disabled_due_to_email_config = False | ||
| if self.email_password_reset_behaviour == "local" and email_config == {}: | ||
| self.local_threepid_emails_disabled_due_to_config = False | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if self.email_threepid_behaviour == "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.password_resets_were_disabled_due_to_email_config = True | ||
| self.local_threepid_emails_disabled_due_to_config = True | ||
|
|
||
| self.email_password_reset_behaviour = "off" | ||
| self.email_threepid_behaviour = "off" | ||
|
|
||
| # Get lifetime of a validation token in milliseconds | ||
| self.email_validation_token_lifetime = self.parse_duration( | ||
|
|
@@ -96,7 +97,7 @@ def read_config(self, config, **kwargs): | |
| if ( | ||
| self.email_enable_notifs | ||
| or account_validity_renewal_enabled | ||
| or self.email_password_reset_behaviour == "local" | ||
| or self.email_threepid_behaviour == "local" | ||
| ): | ||
| # make sure we can import the required deps | ||
| import jinja2 | ||
|
|
@@ -106,7 +107,7 @@ def read_config(self, config, **kwargs): | |
| jinja2 | ||
| bleach | ||
|
|
||
| if self.email_password_reset_behaviour == "local": | ||
| if self.email_threepid_behaviour == "local": | ||
| required = ["smtp_host", "smtp_port", "notif_from"] | ||
|
|
||
| missing = [] | ||
|
|
@@ -125,40 +126,63 @@ 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_password_reset_failure_template = email_config.get( | ||
| "password_reset_failure_template", "password_reset_failure.html" | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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" | ||
| ) | ||
| self.email_registration_template_failure_html = email_config.get( | ||
| "registration_template_failure_html", "registration_failure.html" | ||
| ) | ||
| # This template does not support any replaceable variables, so we will | ||
| # read it from the disk once during setup | ||
| email_password_reset_success_template = email_config.get( | ||
| "password_reset_success_template", "password_reset_success.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_password_reset_failure_template, | ||
| email_password_reset_success_template, | ||
| 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): | ||
| raise ConfigError("Unable to find template file %s" % (p,)) | ||
|
|
||
| # Retrieve content of web templates | ||
| filepath = os.path.join( | ||
| self.email_template_dir, email_password_reset_success_template | ||
| self.email_template_dir, email_password_reset_template_success_html | ||
| ) | ||
| self.email_password_reset_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 = self.read_file( | ||
| filepath, "email.registration_template_success_html" | ||
| ) | ||
|
|
||
| if self.email_enable_notifs: | ||
| required = [ | ||
|
|
@@ -239,19 +263,6 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs): | |
| # # | ||
| # riot_base_url: "http://localhost/riot" | ||
| # | ||
| # # Enable sending password reset emails via the configured, trusted | ||
| # # identity servers | ||
| # # | ||
| # # IMPORTANT! This will give a malicious or overtaken identity server | ||
| # # the ability to reset passwords for your users! Make absolutely sure | ||
| # # that you want to do this! It is strongly recommended that password | ||
| # # reset emails be sent by the homeserver instead | ||
| # # | ||
| # # If this option is set to false and SMTP options have not been | ||
| # # configured, resetting user passwords via email will be disabled | ||
| # # | ||
| # #trust_identity_server_for_password_resets: false | ||
| # | ||
| # # Configure the time that a validation email or text message code | ||
| # # will expire after sending | ||
| # # | ||
|
|
@@ -288,4 +299,10 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs): | |
| # # | ||
| # #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.