This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow password providers to bind emails #4947
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add ability for password provider modules to bind email addresses to users upon registration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,7 @@ def register( | |
user_type=None, | ||
default_display_name=None, | ||
address=None, | ||
bind_emails=[], | ||
): | ||
"""Registers a new client on the server. | ||
|
||
|
@@ -172,6 +173,7 @@ def register( | |
default_display_name (unicode|None): if set, the new user's displayname | ||
will be set to this. Defaults to 'localpart'. | ||
address (str|None): the IP address used to perform the registration. | ||
bind_emails (List[str]): list of emails to bind to this account. | ||
Returns: | ||
A tuple of (user_id, access_token). | ||
Raises: | ||
|
@@ -261,6 +263,10 @@ def register( | |
if not self.hs.config.user_consent_at_registration: | ||
yield self._auto_join_rooms(user_id) | ||
|
||
# Bind any specified emails to this account | ||
for email in bind_emails: | ||
yield self.bind_email_to_account(user_id, email) | ||
|
||
defer.returnValue((user_id, token)) | ||
|
||
@defer.inlineCallbacks | ||
|
@@ -406,6 +412,32 @@ def register_email(self, threepidCreds): | |
403, "Third party identifier is not allowed" | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def bind_email_to_account(self, user_id, email, validated_at=None): | ||
"""Binds an email address with the registered identity service. | ||
|
||
Args: | ||
user_id (str): The user id of the user to bind the email to. | ||
email (str): The email to bind. | ||
validated_at (int|None): Time to mark emails validated at. If | ||
`None`, the current time is used. | ||
|
||
Returns: | ||
Deferred | ||
""" | ||
|
||
# generate threepid dict | ||
threepid_dict = { | ||
"medium": "email", | ||
"address": email, | ||
"validated_at": self.hs.get_clock().time_msec(), | ||
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. you are ignoring the |
||
} | ||
|
||
# Bind email to new account | ||
yield self._register_email_threepid( | ||
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. for the record: where you have a function which just does some synchronous things and ends up calling an asynchronous function, you can skip
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. Good to know, thanks! |
||
user_id, threepid_dict, None, False, | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def bind_emails(self, user_id, threepidCreds): | ||
"""Links emails with a user ID and informs an identity server. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless you have a reason for factoring this out, i feel like it may as well be inlined.