2017-11-06 11 views
1

나는 python-social-auth/social-app-django을 사용하여 소셜 미디어에 내 웹을 연결합니다. 동일한 계정을 사용하여 등록 할 때 오류를 처리하는 방법을 묻고 싶습니다.Python-auth/Django-Social에서 AuthAlreadyAssociated를 처리하는 방법은 무엇입니까?

예를 들어, 페이스 북을 사용하여 가입하고 트위터를 사용하여 다시 가입했습니다. 두 개의 별도 계정에 성공적으로 등록되었습니다. 내 페이스 북을 사용하여 로그인 한 다음 내 계정 설정 페이지에서 오류 메시지가 표시되기 전에 등록 된 내 트위터에 연결하려고합니다.

"AuthAlreadyAssociated at/oauth/전체/트위터/"나는 다시 내 웹에 리디렉션됩니다 트위터 리디렉션 페이지에서 인증 후

AuthAlreadyAssociated

이 메시지가 나타납니다.

요약하면 다른 계정에 등록 된 계정을 처리하는 방법은 무엇입니까?

내 views.py입니다 :

@login_required 
def settings(request): 
    user = request.user 
    try: 
     github_login = user.social_auth.get(provider='github') 
    except UserSocialAuth.DoesNotExist: 
     github_login = None 

    try: 
     twitter_login = user.social_auth.get(provider='twitter') 
    except UserSocialAuth.DoesNotExist: 
     twitter_login = None 

    try: 
     facebook_login = user.social_auth.get(provider='facebook') 
    except UserSocialAuth.DoesNotExist: 
     facebook_login = None 

    can_disconnect = (user.social_auth.count() > 1 or 
    user.has_usable_password()) 

    return render(request, 'profile/settings.html', { 
     'github_login': github_login, 
     'twitter_login': twitter_login, 
     'facebook_login': facebook_login, 
     'can_disconnect': can_disconnect 
    }) 

그리고 이것은 내 settings.html 템플릿입니다 : 나는 누군가가 솔루션을 제공 할 수 있기를 바랍니다,

{% extends "base.html" %} 
 
{% load crispy_forms_tags %} 
 
{% block title %}Navhi Microblog - Profile{% endblock %} 
 
{% block content %} 
 
<div class="col-lg-12 mx-auto"> 
 
    <br /> 
 
    <div class="card"> 
 
     <div class="card-body"> 
 
      {% include 'profile/base_profile.html' %} 
 
       
 
       <!--Card Body goes here--> 
 
       <div class="card-body"> 
 
        <div class="card"> 
 
         <div class="card-body"> 
 
          {% if github_login %} 
 
           {% if can_disconnect %} 
 
            <form method="post" action="{% url 'social:disconnect' 'github' %}"> 
 
             {% csrf_token %} 
 
             <button class="btn btn-danger btn-block" type="submit">Disconnect from GitHub</button> 
 
            </form> 
 
           {% else %} 
 
            <p class="text-center" style="color: red">You must <a href="{% url 'password' %}">define a password</a> for your account before disconnecting from Github.</<p class="text-center"> 
 
           {% endif %} 
 
          {% else %} 
 
           <a class="btn btn-sm btn-social btn-github btn-block" href="{% url 'social:begin' 'github' %}?next={{ request.path }}"> 
 
            <span class="fa fa-github"></span> Connect to Github 
 
           </a> 
 
          {% endif %} 
 
         </div> 
 
        </div> 
 
        <br /> 
 
        <div class="card"> 
 
         <div class="card-body"> 
 
          {% if twitter_login %} 
 
           {% if can_disconnect %} 
 
            <form method="post" action="{% url 'social:disconnect' 'twitter' %}"> 
 
             {% csrf_token %} 
 
             <button class="btn btn-danger btn-block" type="submit">Disconnect from Twitter</button> 
 
            </form> 
 
           {% else %} 
 
            <p class="text-center" style="color: red">You must <a href="{% url 'password' %}">define a password</a> for your account before disconnecting from Twitter.</p> 
 
           {% endif %} 
 
          {% else %} 
 
           <a class="btn btn-sm btn-social btn-twitter btn-block" href="{% url 'social:begin' 'twitter' %}?next={{ request.path }}"> 
 
            <span class="fa fa-twitter"></span> Connect to Twitter 
 
           </a> 
 
          {% endif %} 
 
         </div> 
 
        </div> 
 
        <br /> 
 
        <div class="card"> 
 
         <div class="card-body"> 
 
          {% if facebook_login %} 
 
           {% if can_disconnect %} 
 
            <form method="post" action="{% url 'social:disconnect' 'facebook' %}"> 
 
             {% csrf_token %} 
 
             <button class="btn btn-danger btn-block" type="submit">Disconnect from Facebook</button> 
 
            </form> 
 
           {% else %} 
 
            <p class="text-center" style="color: red">You must <a href="{% url 'password' %}">define a password</a> for your account before disconnecting from Facebook.</p> 
 
           {% endif %} 
 
          {% else %} 
 
           <a class="btn btn-sm btn-social btn-facebook btn-block" href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}"> 
 
            <span class="fa fa-facebook"></span> Connect to Facebook 
 
           </a> 
 
          {% endif %} 
 
         </div> 
 
        </div> 
 
       </div>   
 
      </div> 
 
     </div> 
 
    </div> 
 
</div> 
 
{% endblock %}
감사합니다 이것을 위해, 그리고 나쁜 영어로 유감스럽게 생각합니다.

+0

가능한 중복 https://stackoverflow.com/questions/13018147/authalreadyassociated-exception-in-django-social-auth : 여기 오버라이드 (override)하는 방법에 대한

더) – Striped

답변