mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-26 17:19:23 -05:00
Allow password providers to bind emails (#4947)
This PR allows password provider modules to bind email addresses when a user is registering and is motivated by matrix-org/matrix-synapse-ldap3#58
This commit is contained in:
parent
248014379e
commit
7a91b9d81c
1
changelog.d/4947.feature
Normal file
1
changelog.d/4947.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add ability for password provider modules to bind email addresses to users upon registration.
|
@ -153,6 +153,7 @@ class RegistrationHandler(BaseHandler):
|
|||||||
user_type=None,
|
user_type=None,
|
||||||
default_display_name=None,
|
default_display_name=None,
|
||||||
address=None,
|
address=None,
|
||||||
|
bind_emails=[],
|
||||||
):
|
):
|
||||||
"""Registers a new client on the server.
|
"""Registers a new client on the server.
|
||||||
|
|
||||||
@ -172,6 +173,7 @@ class RegistrationHandler(BaseHandler):
|
|||||||
default_display_name (unicode|None): if set, the new user's displayname
|
default_display_name (unicode|None): if set, the new user's displayname
|
||||||
will be set to this. Defaults to 'localpart'.
|
will be set to this. Defaults to 'localpart'.
|
||||||
address (str|None): the IP address used to perform the registration.
|
address (str|None): the IP address used to perform the registration.
|
||||||
|
bind_emails (List[str]): list of emails to bind to this account.
|
||||||
Returns:
|
Returns:
|
||||||
A tuple of (user_id, access_token).
|
A tuple of (user_id, access_token).
|
||||||
Raises:
|
Raises:
|
||||||
@ -261,6 +263,21 @@ class RegistrationHandler(BaseHandler):
|
|||||||
if not self.hs.config.user_consent_at_registration:
|
if not self.hs.config.user_consent_at_registration:
|
||||||
yield self._auto_join_rooms(user_id)
|
yield self._auto_join_rooms(user_id)
|
||||||
|
|
||||||
|
# Bind any specified emails to this account
|
||||||
|
current_time = self.hs.get_clock().time_msec()
|
||||||
|
for email in bind_emails:
|
||||||
|
# generate threepid dict
|
||||||
|
threepid_dict = {
|
||||||
|
"medium": "email",
|
||||||
|
"address": email,
|
||||||
|
"validated_at": current_time,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Bind email to new account
|
||||||
|
yield self._register_email_threepid(
|
||||||
|
user_id, threepid_dict, None, False,
|
||||||
|
)
|
||||||
|
|
||||||
defer.returnValue((user_id, token))
|
defer.returnValue((user_id, token))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -74,14 +74,14 @@ class ModuleApi(object):
|
|||||||
return self._auth_handler.check_user_exists(user_id)
|
return self._auth_handler.check_user_exists(user_id)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def register(self, localpart, displayname=None):
|
def register(self, localpart, displayname=None, emails=[]):
|
||||||
"""Registers a new user with given localpart and optional
|
"""Registers a new user with given localpart and optional
|
||||||
displayname.
|
displayname, emails.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
localpart (str): The localpart of the new user.
|
localpart (str): The localpart of the new user.
|
||||||
displayname (str|None): The displayname of the new user. If None,
|
displayname (str|None): The displayname of the new user.
|
||||||
the user's displayname will default to `localpart`.
|
emails (List[str]): Emails to bind to the new user.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Deferred: a 2-tuple of (user_id, access_token)
|
Deferred: a 2-tuple of (user_id, access_token)
|
||||||
@ -90,6 +90,7 @@ class ModuleApi(object):
|
|||||||
reg = self.hs.get_registration_handler()
|
reg = self.hs.get_registration_handler()
|
||||||
user_id, access_token = yield reg.register(
|
user_id, access_token = yield reg.register(
|
||||||
localpart=localpart, default_display_name=displayname,
|
localpart=localpart, default_display_name=displayname,
|
||||||
|
bind_emails=emails,
|
||||||
)
|
)
|
||||||
|
|
||||||
defer.returnValue((user_id, access_token))
|
defer.returnValue((user_id, access_token))
|
||||||
|
Loading…
Reference in New Issue
Block a user