Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Allow HS to send emails when adding an email to the HS #6042

Merged
merged 47 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0e5d92d
Allow HS to send emails when adding an email to the HS
anoadragon453 Sep 16, 2019
92b3246
Add changelog
anoadragon453 Sep 16, 2019
626ebbd
Add changelog
anoadragon453 Sep 17, 2019
8132107
Add 'add threepid' email templates to config. Gen sample config
anoadragon453 Sep 17, 2019
d309ea2
Merge branch 'develop' into anoa/account_3pid_homeserver
anoadragon453 Sep 17, 2019
112d55e
Merge branch 'anoa/account_3pid_homeserver' into anoa/account_3pid_ho…
anoadragon453 Sep 17, 2019
096808b
Add 3PID bind sytests to blacklist temporarily
anoadragon453 Sep 17, 2019
268bbbb
Prevent /account/3pid from binding to an identity server
anoadragon453 Sep 17, 2019
dda5137
Correct some small issues and fix bug
anoadragon453 Sep 17, 2019
8e2481b
Address review comments
anoadragon453 Sep 18, 2019
f6c0d5c
Remove the requirement for a medium argument
anoadragon453 Sep 18, 2019
923736f
Handle the homeserver disabling email validation
anoadragon453 Sep 18, 2019
4fc7796
Remove blacklist
anoadragon453 Sep 18, 2019
15bf108
Fix add_threepid template default values in emailconfig
anoadragon453 Sep 18, 2019
d20feec
Remove redundant logging
anoadragon453 Sep 18, 2019
0e5c7bf
Undo fix on password reset POST submit_token endpoint
anoadragon453 Sep 18, 2019
46da943
Update synapse/storage/registration.py
anoadragon453 Sep 18, 2019
3941439
Use an assert instead of if-statement with SynapseError
anoadragon453 Sep 18, 2019
0200e41
Remove trailing slashes from submit_token endpoint patterns
anoadragon453 Sep 18, 2019
c8dbf53
python3 super()
anoadragon453 Sep 18, 2019
d32724b
Remove self.hs set from AddThreepidSubmitTokenServlet
anoadragon453 Sep 18, 2019
0812664
Clarify changelog
anoadragon453 Sep 18, 2019
9309ca5
Merge branch 'anoa/account_3pid_homeserver_send_email' of github.com:…
anoadragon453 Sep 18, 2019
46e6d92
Sanity check ThreepidBehaviour.REMOTE on submit_token endpoint
anoadragon453 Sep 18, 2019
b37d71c
Re-blacklist tests
anoadragon453 Sep 18, 2019
16eb35d
Factor out removing id_server from msisdn
anoadragon453 Sep 18, 2019
16d7ec2
Remove POST /add_threepid/<medium>/submit_token
anoadragon453 Sep 18, 2019
ab1ae2f
Ensure REMOTE vs LOCAL ThreepidBehaviour is handled
anoadragon453 Sep 19, 2019
1be82f8
URL encode validation link parameters
anoadragon453 Sep 19, 2019
317332e
Move jinja failure template loading into servlet constructor
anoadragon453 Sep 19, 2019
59e0aad
Make add_threepid submit_token email-only
anoadragon453 Sep 19, 2019
882642e
Make get_threepid_validation_session require client_secret
anoadragon453 Sep 19, 2019
1464f14
Update changelog entry
anoadragon453 Sep 19, 2019
fb9c582
Set email
anoadragon453 Sep 19, 2019
f62ddf6
Make sure templates only get loaded when necessary
anoadragon453 Sep 19, 2019
0dcdfbb
Remove unnecessary vars and params
anoadragon453 Sep 20, 2019
d683ae5
Ensure link is not a tuple
anoadragon453 Sep 20, 2019
f62a27c
Pull if validation_session out of helper method
anoadragon453 Sep 20, 2019
ac92a58
this confused me for so long
anoadragon453 Sep 20, 2019
38a543c
Don't force https on account_threepid_delegates
anoadragon453 Sep 20, 2019
2f296c7
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/acc…
anoadragon453 Sep 20, 2019
b12e51a
Ensure we catch HttpResponseException when calling to id servers
anoadragon453 Sep 20, 2019
1267abd
Unpack response from identity server to check for errors
anoadragon453 Sep 20, 2019
b3bf430
Remove prefix nonsense
anoadragon453 Sep 20, 2019
227ec33
Factor out password_reset trailing slash change
anoadragon453 Sep 20, 2019
4efc108
Address review comments
anoadragon453 Sep 20, 2019
7c351df
validation_session cannot be None
anoadragon453 Sep 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6042.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow homeserver to handle threepid validation itself when adding a threepid to a user's account.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,12 @@ password_config:
# #registration_template_html: registration.html
# #registration_template_text: registration.txt
#
# # Templates for validation emails sent by the homeserver when adding an email to
# # your user account
# #
# #add_threepid_template_html: add_threepid.html
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
# #add_threepid_template_text: add_threepid.txt
#
# # Templates for password reset success and failure pages that a user
# # will see after attempting to reset their password
# #
Expand All @@ -1272,6 +1278,12 @@ password_config:
# #
# #registration_template_success_html: registration_success.html
# #registration_template_failure_html: registration_failure.html
#
# # Templates for success and failure pages that a user will see after attempting
# # to add an email or phone to their account
# #
# #add_threepid_success_html: add_threepid.html
# #add_threepid_failure_html: add_threepid.html


#password_providers:
Expand Down
36 changes: 36 additions & 0 deletions synapse/config/emailconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,22 @@ def read_config(self, config, **kwargs):
self.email_registration_template_text = email_config.get(
"registration_template_text", "registration.txt"
)
self.email_add_threepid_template_html = email_config.get(
"add_threepid_template_html", "add_threepid.html"
)
self.email_add_threepid_template_text = email_config.get(
"add_threepid_template_text", "add_threepid.txt"
)

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"
)
self.email_add_threepid_template_failure_html = email_config.get(
"add_threepid_template_failure_html", "add_threepid_failure.html"
)

# These templates do not support any placeholder variables, so we
# will read them from disk once during setup
Expand All @@ -184,16 +194,24 @@ def read_config(self, config, **kwargs):
email_registration_template_success_html = email_config.get(
"registration_template_success_html", "registration_success.html"
)
email_add_threepid_template_success_html = email_config.get(
"add_threepid_template_success_html", "add_threepid_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_add_threepid_template_html,
self.email_add_threepid_template_text,
self.email_password_reset_template_failure_html,
self.email_registration_template_failure_html,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed to be missing :|

self.email_add_threepid_template_failure_html,
email_password_reset_template_success_html,
email_registration_template_success_html,
email_add_threepid_template_success_html,
]:
p = os.path.join(self.email_template_dir, f)
if not os.path.isfile(p):
Expand All @@ -212,6 +230,12 @@ def read_config(self, config, **kwargs):
self.email_registration_template_success_html_content = self.read_file(
filepath, "email.registration_template_success_html"
)
filepath = os.path.join(
self.email_template_dir, email_add_threepid_template_success_html
)
self.email_add_threepid_template_success_html_content = self.read_file(
filepath, "email.add_threepid_template_success_html"
)

if self.email_enable_notifs:
required = [
Expand Down Expand Up @@ -328,6 +352,12 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
# #registration_template_html: registration.html
# #registration_template_text: registration.txt
#
# # Templates for validation emails sent by the homeserver when adding an email to
# # your user account
# #
# #add_threepid_template_html: add_threepid.html
# #add_threepid_template_text: add_threepid.txt
#
# # Templates for password reset success and failure pages that a user
# # will see after attempting to reset their password
# #
Expand All @@ -339,6 +369,12 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
# #
# #registration_template_success_html: registration_success.html
# #registration_template_failure_html: registration_failure.html
#
# # Templates for success and failure pages that a user will see after attempting
# # to add an email or phone to their account
# #
# #add_threepid_success_html: add_threepid.html
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
# #add_threepid_failure_html: add_threepid.html
"""


Expand Down
28 changes: 28 additions & 0 deletions synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,34 @@ def send_registration_mail(self, email_address, token, client_secret, sid):
template_vars,
)

@defer.inlineCallbacks
def send_add_threepid_mail(self, email_address, token, client_secret, sid):
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
"""Send an email with a validation link to a user for adding a 3pid to their account

Args:
email_address (str): Email address we're sending the validation link to

token (str): Unique token generated by the server to verify the email was received

client_secret (str): Unique token generated by the client to group together
multiple email sending attempts

sid (str): The generated session ID
"""
link = (
self.hs.config.public_baseurl
+ "_matrix/client/unstable/add_threepid/email/submit_token"
"?token=%s&client_secret=%s&sid=%s" % (token, client_secret, sid)
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
)

template_vars = {"link": link}

yield self.send_email(
email_address,
"[%s] Validate Your Email" % self.hs.config.server_name,
template_vars,
)

@defer.inlineCallbacks
def send_notification_mail(
self, app_id, user_id, email_address, push_actions, reason
Expand Down
9 changes: 9 additions & 0 deletions synapse/res/templates/add_threepid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<body>
<p>A request to add an email address to your Matrix account has been received. If this was you, please click the link below to confirm adding this email:</p>

<a href="{{ link }}">{{ link }}</a>

<p>If this was not you, you can safely ignore this email. Thank you.</p>
</body>
</html>
6 changes: 6 additions & 0 deletions synapse/res/templates/add_threepid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A request to add an email address to your Matrix account has been received. If this was you,
please click the link below to confirm adding this email:

{{ link }}

If this was not you, you can safely ignore this email. Thank you.
8 changes: 8 additions & 0 deletions synapse/res/templates/add_threepid_failure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head></head>
<body>
<p>The request failed for the following reason: {{ failure_reason }}.</p>

<p>No changes have been made to your account.</p>
</body>
</html>
6 changes: 6 additions & 0 deletions synapse/res/templates/add_threepid_success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<head></head>
<body>
<p>Your email has now been validated, please return to your client. You may now close this window.</p>
</body>
</html>
Loading