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

Это должно сделать трюк.

Смежные вопросы