Skip to content

Commit 43340f0

Browse files
author
Ben Rogers-Newsome
committed
Better variable naming for user in complete
The user variable was being re-assigned based on itself multiple times. In reality there are 3 variables here: The user we pass to the function, the user we pass into the pipeline and the user we get back out of the pipeline. These are 3 separate variables (it just so happens that we don't care about the old one once we create the new one). Separating the variables out into three makes it much clearer what is going on with the pipeline. Made a similar name change for the added user_authenticated variable.
1 parent a8a773e commit 43340f0

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

social_core/actions.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ def do_complete(backend, login, user=None, redirect_name='next',
3333
*args, **kwargs):
3434
data = backend.strategy.request_data()
3535

36-
is_authenticated = user_is_authenticated(user)
37-
user = user if is_authenticated else None
36+
is_authenticated_pre_pipeline = user_is_authenticated(user)
37+
pre_pipeline_user = user if is_authenticated else None
3838

39-
partial = partial_pipeline_data(backend, user, *args, **kwargs)
39+
partial = partial_pipeline_data(backend, pre_pipeline_user, *args, **kwargs)
4040
if partial:
41-
user = backend.continue_pipeline(partial)
41+
post_pipeline_user = backend.continue_pipeline(partial)
4242
# clean partial data after usage
4343
backend.strategy.clean_partial_pipeline(partial.token)
4444
else:
45-
user = backend.complete(user=user, *args, **kwargs)
45+
post_pipeline_user = backend.complete(user=pre_pipeline_user, *args, **kwargs)
4646

4747
# pop redirect value before the session is trashed on login(), but after
4848
# the pipeline so that the pipeline can change the redirect if needed
@@ -52,23 +52,23 @@ def do_complete(backend, login, user=None, redirect_name='next',
5252
# check if the output value is something else than a user and just
5353
# return it to the client
5454
user_model = backend.strategy.storage.user.user_model()
55-
if user and not isinstance(user, user_model):
56-
return user
55+
if post_pipeline_user and not isinstance(post_pipeline_user, user_model):
56+
return post_pipeline_user
5757

58-
is_authenticated = user_is_authenticated(user)
58+
is_authenticated_post_pipeline = user_is_authenticated(post_pipeline_user)
5959
if is_authenticated:
60-
if not user:
60+
if not post_pipeline_user:
6161
url = setting_url(backend, redirect_value, 'LOGIN_REDIRECT_URL')
6262
else:
6363
url = setting_url(backend, redirect_value,
6464
'NEW_ASSOCIATION_REDIRECT_URL',
6565
'LOGIN_REDIRECT_URL')
66-
elif user:
67-
if user_is_active(user):
66+
elif post_pipeline_user:
67+
if user_is_active(post_pipeline_user):
6868
# catch is_new/social_user in case login() resets the instance
69-
is_new = getattr(user, 'is_new', False)
70-
social_user = user.social_user
71-
login(backend, user, social_user)
69+
is_new = getattr(post_pipeline_user, 'is_new', False)
70+
social_user = post_pipeline_user.social_user
71+
login(backend, post_pipeline_user, social_user)
7272
# store last login backend name in session
7373
backend.strategy.session_set('social_auth_last_login_backend',
7474
social_user.provider)
@@ -83,8 +83,8 @@ def do_complete(backend, login, user=None, redirect_name='next',
8383
'LOGIN_REDIRECT_URL')
8484
else:
8585
if backend.setting('INACTIVE_USER_LOGIN', False):
86-
social_user = user.social_user
87-
login(backend, user, social_user)
86+
social_user = post_pipeline_user.social_user
87+
login(backend, post_pipeline_user, social_user)
8888
url = setting_url(backend, 'INACTIVE_USER_URL', 'LOGIN_ERROR_URL',
8989
'LOGIN_URL')
9090
else:

0 commit comments

Comments
 (0)