mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 16:54:56 -04:00
Initialise user displayname from SAML2 data (#4272)
When we register a new user from SAML2 data, initialise their displayname correctly.
This commit is contained in:
parent
35e13477cf
commit
30da50a5b8
6 changed files with 39 additions and 15 deletions
|
@ -126,6 +126,7 @@ class RegistrationHandler(BaseHandler):
|
|||
make_guest=False,
|
||||
admin=False,
|
||||
threepid=None,
|
||||
default_display_name=None,
|
||||
):
|
||||
"""Registers a new client on the server.
|
||||
|
||||
|
@ -140,6 +141,8 @@ class RegistrationHandler(BaseHandler):
|
|||
since it offers no means of associating a device_id with the
|
||||
access_token. Instead you should call auth_handler.issue_access_token
|
||||
after registration.
|
||||
default_display_name (unicode|None): if set, the new user's displayname
|
||||
will be set to this. Defaults to 'localpart'.
|
||||
Returns:
|
||||
A tuple of (user_id, access_token).
|
||||
Raises:
|
||||
|
@ -169,6 +172,13 @@ class RegistrationHandler(BaseHandler):
|
|||
user = UserID(localpart, self.hs.hostname)
|
||||
user_id = user.to_string()
|
||||
|
||||
if was_guest:
|
||||
# If the user was a guest then they already have a profile
|
||||
default_display_name = None
|
||||
|
||||
elif default_display_name is None:
|
||||
default_display_name = localpart
|
||||
|
||||
token = None
|
||||
if generate_token:
|
||||
token = self.macaroon_gen.generate_access_token(user_id)
|
||||
|
@ -178,10 +188,7 @@ class RegistrationHandler(BaseHandler):
|
|||
password_hash=password_hash,
|
||||
was_guest=was_guest,
|
||||
make_guest=make_guest,
|
||||
create_profile_with_localpart=(
|
||||
# If the user was a guest then they already have a profile
|
||||
None if was_guest else user.localpart
|
||||
),
|
||||
create_profile_with_displayname=default_display_name,
|
||||
admin=admin,
|
||||
)
|
||||
|
||||
|
@ -203,13 +210,15 @@ class RegistrationHandler(BaseHandler):
|
|||
yield self.check_user_id_not_appservice_exclusive(user_id)
|
||||
if generate_token:
|
||||
token = self.macaroon_gen.generate_access_token(user_id)
|
||||
if default_display_name is None:
|
||||
default_display_name = localpart
|
||||
try:
|
||||
yield self.store.register(
|
||||
user_id=user_id,
|
||||
token=token,
|
||||
password_hash=password_hash,
|
||||
make_guest=make_guest,
|
||||
create_profile_with_localpart=user.localpart,
|
||||
create_profile_with_displayname=default_display_name,
|
||||
)
|
||||
except SynapseError:
|
||||
# if user id is taken, just generate another
|
||||
|
@ -300,7 +309,7 @@ class RegistrationHandler(BaseHandler):
|
|||
user_id=user_id,
|
||||
password_hash="",
|
||||
appservice_id=service_id,
|
||||
create_profile_with_localpart=user.localpart,
|
||||
create_profile_with_displayname=user.localpart,
|
||||
)
|
||||
defer.returnValue(user_id)
|
||||
|
||||
|
@ -478,7 +487,7 @@ class RegistrationHandler(BaseHandler):
|
|||
user_id=user_id,
|
||||
token=token,
|
||||
password_hash=password_hash,
|
||||
create_profile_with_localpart=user.localpart,
|
||||
create_profile_with_displayname=user.localpart,
|
||||
)
|
||||
else:
|
||||
yield self._auth_handler.delete_access_tokens_for_user(user_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue