mirror of https://github.com/zulip/zulip.git
auth: Restructure code handling no name data sent by auth backend.
Co-authored-by: Mateusz Mandera <mateusz.mandera@zulip.com>
This commit is contained in:
parent
4afce5d94d
commit
ea225bb9b8
|
@ -1181,21 +1181,17 @@ def social_associate_user_helper(backend: BaseAuth, return_data: Dict[str, Any],
|
||||||
user_profile = common_get_active_user(validated_email, realm, return_data)
|
user_profile = common_get_active_user(validated_email, realm, return_data)
|
||||||
|
|
||||||
full_name = kwargs['details'].get('fullname')
|
full_name = kwargs['details'].get('fullname')
|
||||||
first_name = kwargs['details'].get('first_name', '')
|
first_name = kwargs['details'].get('first_name')
|
||||||
last_name = kwargs['details'].get('last_name', '')
|
last_name = kwargs['details'].get('last_name')
|
||||||
if full_name is None:
|
if all(name is None for name in [full_name, first_name, last_name]) and backend.name != "apple":
|
||||||
if not first_name and not last_name:
|
# Apple authentication provides the user's name only the very first time a user tries to login.
|
||||||
# We need custom code here for any social auth backends
|
# So if the user aborts login or otherwise is doing this the second time,
|
||||||
# that don't provide name details feature.
|
# we won't have any name data. So, this case is handled with the code below
|
||||||
if (backend.name == 'apple'):
|
# setting full name to empty string.
|
||||||
# Apple authentication provides the user's name only
|
|
||||||
# the very first time a user tries to login. So if
|
# We need custom code here for any social auth backends
|
||||||
# the user aborts login or otherwise is doing this the
|
# that don't provide name details feature.
|
||||||
# second time, we won't have any name data. We handle
|
raise AssertionError("Social auth backend doesn't provide name")
|
||||||
# this by setting full_name to be the empty string.
|
|
||||||
full_name = ""
|
|
||||||
else:
|
|
||||||
raise AssertionError("Social auth backend doesn't provide name")
|
|
||||||
|
|
||||||
if full_name:
|
if full_name:
|
||||||
return_data["full_name"] = full_name
|
return_data["full_name"] = full_name
|
||||||
|
|
Loading…
Reference in New Issue