2014-10-22 78 views
0

我使用python-social-auth和我的管道如下:蟒蛇 - 社会 - 身份验证 - 更新电子邮件地址

'social.pipeline.social_auth.social_details', 
'social.pipeline.social_auth.social_uid', 
'social.pipeline.social_auth.auth_allowed', 
'social.pipeline.social_auth.social_user', 
'social.pipeline.user.get_username', 
'social.pipeline.social_auth.associate_by_email', 
'social.pipeline.user.create_user', 
'social.pipeline.social_auth.associate_user', 
'social.pipeline.social_auth.load_extra_data', 
'social.pipeline.user.user_details', 

我想get_username,我要问他的电子邮件地址的用户后添加的形式。我没有从后端提供商处获得一个。我想把这个电子邮件地址,并将该帐户与该电子邮件地址相关联。

这怎么可能?函数应该如何?

回答

1

功能:

from django.shortcuts import render 

from social.pipeline.partial import partial 


@partial 
def require_email(strategy, backend, details, user=None, is_new=False, *args, **kwargs): 
    if is_new and not details.get('email'): 
     email = strategy.request_data().get('email') 
     if email: 
      details['email'] = email 
     else: 
      return render(strategy.request, 'require_email.html', backend=backend.name) 

模板:

<form method="post" action="/complete/{{ backend }}/">{% csrf_token %} 
    <label for="email">Email:</label>   
    <input id="email" type="email" placeholder="Your email address"> 
    <button>Submit</button> 
</form> 

这应该做的伎俩。