部分管道要求用户的电话号码 [英] Partial Pipeline to ask user's phone number

查看:159
本文介绍了部分管道要求用户的电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建部分管道,以便在注册时获取用户的电话号码,并跳过后续登录的步骤。我的部分管道如下所示:

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

welcome.html 有一个表单。相应的视图如下所示:

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.

推荐答案

您可能可以让用户使用

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).

这篇关于部分管道要求用户的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆