Answer the question
In order to leave comments, you need to log in
How to properly redirect in the pipeline if the user is new (python-social-auth)?
Good afternoon.
I recently started learning Django (v. 1.8) by creating a small project. The project requires authorization through a Steam account, for which I use the python-social-auth library .
I made my user model, which contains account data. Steam records. Wrote a pipeline that detects a new user or not, and, depending on this, creates or updates the user model in Django.
In case the user is new, I would like to send him to the profile filling page (email, name, etc.), but I do not quite understand how best to do this. If I use HttpResponseRedirect, then my user gets into the view as anonymous.
pipeline code:
# -*- coding: utf-8 -*-
from MySteam.settings import SA_USER_LEVEL
USER_FIELDS = ['email']
def update_or_create_user(strategy, details, backend, uid, user=None, *args, **kwargs):
strategy.provider = 'steam'
try:
get_user = SteamUser.objects.get(steam_id=uid)
except SteamUser.DoesNotExist:
get_user = None
if get_user:
get_user.update_steam_data()
return {
'is_new': False,
'social': strategy,
'user': get_user,
'new_association': False
}
else:
user = SteamUser.objects.create_user()
return {
'is_new': True,
'social': strategy,
'user': user,
'new_association': False
}
Answer the question
In order to leave comments, you need to log in
The solution was found in the library documentation :
SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/new-users-redirect-url/'
This variable is responsible for redirecting new users.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question