2017-11-06 2 views
1

私はこのウェブサイトをソーシャルメディアに接続するのにpython-social-auth/social-app-djangoを使用します。 同じアカウントを使用してサインアップする際のエラー処理方法を教えてください。Python-auth/Django-SocialでAuthAlreadyAssociatedを処理するには?

たとえば、Facebookにサインアップして、Twitterで再び登録しました。私はFacebookにログインしてアカウント設定ページにログインしたときに、登録されているTwitterに接続してエラーメッセージを表示します。

"AuthAlreadyAssociated at/oauth /完全/さえずり/」私はそれが戻って自分のWebにリダイレクトされるTwitterのリダイレクトページに許可した後

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 ) – Striped

答えて

0

あなたの質問はここで回答されています AuthAlreadyAssociated Exception in Django Social Auth

基本的な答えはsocial_auth.middleware.SocialAuthExceptionMiddlewareクラスのデフォルトの方法process_exception()をオーバーライドして、あなたのsettings.pyに、このミドルウェアを追加することです。ここで上書きする方法について

詳細:[ジャンゴ社会認証でAuthAlreadyAssociated例外]のHow do I handle exceptions on Python Social Auth

関連する問題