0

I am creating a partial pipeline to get user's phone number on signup and skip the step on subsequent logins. My partial pipeline looks like this:

@partial
def other_info(strategy, details, user=None, is_new=False, *args, **kwargs):
    if is_new or not details.get('email'):
        request = kwargs['request']
        return redirect('require_phone')
    else:
        return

On the page-welcome.html there is a form. Corresponding view looks like this:

def require_phone(request):
    if request.method == 'POST':
        phone = request.POST.get('phone',None)
        user = User.objects.get(username = request.user.username)
        if phone is not None:
            up = UserProfile.objects.get_or_create(user=request.user,   
                                                   phone = phone)
            up.save()
        backend = request.session['partial_pipeline']['backend']
        return redirect('social:complete', backend=backend)
    else:
        return render(request,'app/page-welcome.html')

The problem is, the request object is not passed correctly to the view and hence the user shows anonymous. I am not able to access user object and hence cannot save phone no.

Maxsteel
  • 1,922
  • 4
  • 30
  • 55

1 Answers1

0

You might be able to get the user with

user = User.objects.get(id=request.session['partial_pipeline']['kwargs']['user'])

and then update this object, instead of trying to get it from the request (which will not work during the pipeline).

webjunkie
  • 6,891
  • 7
  • 46
  • 43