2014-10-22 119 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> 

這應該做的伎倆。

相關問題