Reputation: 1208
I'm using django-social-auth by @Omab for my site.
In the settings, I have SOCIAL_AUTH_NEW_USER_REDIRECT_URL
set to, say, /profile
. My question is, in the view, how do I check if the user is new? Is there a variable that I can access?
Upvotes: 1
Views: 1925
Reputation: 1208
Found the solution.
The variable is_new
is set in the request.session
variable. You can access it as follows:
name = setting('SOCIAL_AUTH_PARTIAL_PIPELINE_KEY', 'partial_pipeline')
if name in request.session:
if request.session[name]['kwargs']['is_new'] == True:
#Do something.
Thanks for your answers!
Upvotes: 1
Reputation: 966
I am assuming that SOCIAL_AUTH_LOGIN_REDIRECT_URL
and SOCIAL_AUTH_NEW_USER_REDIRECT_URL
both point to /profile
. And you want to deferenciate between users being directed to /profile
who where sent there using SOCIAL_AUTH_NEW_USER_REDIRECT_URL
.
The simplest way to do this would be to have a new url pattern like this:
urls = [
(r'^profile/$', 'profile'),
(r'^profile/new/$', 'profile', {'new_user': True}),
]
urlpatterns = patterns('project.app.views', *urls)
from django.shortcuts import render
def profile(request, new_user=False):
if new:
# if user is new code
return render(request, 'path/to/template.html', {'new_user': new_user})
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/profile'
SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/profile/new'
Read about it here: https://docs.djangoproject.com/en/1.5/topics/http/urls/#passing-extra-options-to-view-functions
:)
Upvotes: 2