Python Social Auth,扩展断开管道

标签 python django python-social-auth

我有一个用户资料表,它有 fb_id、tw_id。所以我正在检查用户是否连接了他们的社交帐户。当用户断开其中一个帐户时,我需要更新这些列。

SOCIAL_AUTH_DISCONNECT_PIPELINE = (
    'social.pipeline.disconnect.allowed_to_disconnect',
    'social.pipeline.disconnect.get_entries',
    'social.pipeline.disconnect.revoke_tokens',
    'social.pipeline.disconnect.disconnect',
    'profiles.utils.disconnect',
)

所以我在我的个人资料应用程序中添加了一个名为 disconnect 的函数,因为它引用了 here .

def disconnect(backend, user, response, *args, **kwargs):
    if Profiles.objects.filter(user=user).exists():
        if backend.name == 'facebook':
            profile=Profiles.objects.get(user=user)
            profile.fb_id = ''
            profile.save()

        if backend.name == 'twitter':
            profile=Profiles.objects.get(user=user)
            profile.tw_id = ''
            profile.save()

        if backend.name == 'instagram':
            profile=Profiles.objects.get(user=user)
            new_profile.in_id = ''
            profile.save()

当我尝试断开我的帐户时,出现此错误:

TypeError at /disconnect/facebook/
disconnect() takes at least 3 arguments (2 given)
Request Method: POST
Request URL:    /disconnect/facebook/
Django Version: 1.8.2
Exception Type: TypeError
Exception Value:    
disconnect() takes at least 3 arguments (2 given)

这是我第一次使用 python_social_auth,我们将不胜感激。

最佳答案

试试这个

SOCIAL_AUTH_DISCONNECT_PIPELINE = (
    'social.pipeline.disconnect.allowed_to_disconnect',
    'social.pipeline.disconnect.get_entries',
    'social.pipeline.disconnect.revoke_tokens',
    # 'social.pipeline.disconnect.disconnect',  # comment
    'profiles.utils.custom_pipeline',
)

custom_pipeline.py

def disconnect(strategy, entries, user_storage, *args, **kwargs):        
    for entry in entries:
        user_storage.disconnect(entry)
    backend = kwargs.get('name')

    profile=Profiles.objects.get(user=entries[0].user)
    if backend == 'facebook':
        profile.fb_id = ''
    elif backend == 'twitter':
        profile.tw_id = ''
    elif backend == 'instagram':
        new_profile.in_id = ''
    profile.save()

最好的!

关于Python Social Auth,扩展断开管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31039457/

相关文章:

python - 为什么调用文件 write() 方法不起作用?

python - 如何获取文本小部件的当前光标位置

python - 使 my_average(a, b) 与定义了 f_add 和 d_div 的任何 a 和 b 一起使用。以及内置函数

Django 信号无法正常工作

python - Facebook 不返回电子邮件 Python Social Auth

python - 在 Django 中同时使用 python-social-auth 和电子邮件注册来复制电子邮件

python - 获取最小 MSE python 的路径

django - 在 Ubuntu WSL2 上连接到本地主机的问题

android - 在多平台项目中将用户图像存储为二进制数据与静态文件的性能影响?

django - python-social-auth,无需断开连接即可注销