Skip to content

Commit

Permalink
Better variable naming for user in complete
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ben Rogers-Newsome committed Jan 5, 2022
1 parent a8a773e commit a65bd7e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions social_core/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ def do_complete(backend, login, user=None, redirect_name='next',
*args, **kwargs):
data = backend.strategy.request_data()

is_authenticated = user_is_authenticated(user)
user = user if is_authenticated else None
is_authenticated_pre_pipeline = user_is_authenticated(user)
pre_pipeline_user = user if is_authenticated_pre_pipeline else None

partial = partial_pipeline_data(backend, user, *args, **kwargs)
partial = partial_pipeline_data(backend, pre_pipeline_user, *args, **kwargs)
if partial:
user = backend.continue_pipeline(partial)
post_pipeline_user = backend.continue_pipeline(partial)
# clean partial data after usage
backend.strategy.clean_partial_pipeline(partial.token)
else:
user = backend.complete(user=user, *args, **kwargs)
post_pipeline_user = backend.complete(user=pre_pipeline_user, *args, **kwargs)

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

is_authenticated = user_is_authenticated(user)
if is_authenticated:
if not user:
is_authenticated_post_pipeline = user_is_authenticated(post_pipeline_user)
if is_authenticated_post_pipeline:
if not post_pipeline_user:
url = setting_url(backend, redirect_value, 'LOGIN_REDIRECT_URL')
else:
url = setting_url(backend, redirect_value,
'NEW_ASSOCIATION_REDIRECT_URL',
'LOGIN_REDIRECT_URL')
elif user:
if user_is_active(user):
elif post_pipeline_user:
if user_is_active(post_pipeline_user):
# catch is_new/social_user in case login() resets the instance
is_new = getattr(user, 'is_new', False)
social_user = user.social_user
login(backend, user, social_user)
is_new = getattr(post_pipeline_user, 'is_new', False)
social_user = post_pipeline_user.social_user
login(backend, post_pipeline_user, social_user)
# store last login backend name in session
backend.strategy.session_set('social_auth_last_login_backend',
social_user.provider)
Expand All @@ -83,8 +83,8 @@ def do_complete(backend, login, user=None, redirect_name='next',
'LOGIN_REDIRECT_URL')
else:
if backend.setting('INACTIVE_USER_LOGIN', False):
social_user = user.social_user
login(backend, user, social_user)
social_user = post_pipeline_user.social_user
login(backend, post_pipeline_user, social_user)
url = setting_url(backend, 'INACTIVE_USER_URL', 'LOGIN_ERROR_URL',
'LOGIN_URL')
else:
Expand Down

0 comments on commit a65bd7e

Please sign in to comment.