管道django社会认证

时间:2014-03-13 16:18:13

标签: django django-socialauth

这是我与django的第一个项目,我安装了django social auth并且工作正常但是当我使用自定义管道时,注册转到/ login-error

使用python 2.6 django 1.6.2

#settings.py

SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.user.create_user',
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details',
'social_auth.backends.pipeline.misc.save_status_to_session',
'app.pipelines.get_user_avatar'
)


#pipelines.py

def get_user_avatar(strategy, user, response, is_new=False,*args,**kwargs):
url = None
if is_new and strategy.backend.name == 'facebook':
    url = "http://graph.facebook.com/%s/picture?type=large" % response['id']
if url:
    profile = user.get_profile()
    profile.photo = url # depends on where you saved it
    profile.save()


#models.py

from django.db import models
from django.contrib.auth.models import User

class Profile(models.Model):
    user = models.ForeignKey(User)
    points = models.IntegerField(default = 0)
    photo = models.URLField()

2 个答案:

答案 0 :(得分:1)

您需要使用python social auth代替。 Django社会认证已被弃用。

答案 1 :(得分:1)

您的代码中有一些细节不正确。

    只有当您计划将用户重定向到另一个视图/表单时才会使用
  1. 'social_auth.backends.pipeline.misc.save_status_to_session'(打破处理并稍后继续)
  2. 您的自定义管道正在使用strategy,这是[{1}}中的参数,但不是python-social-auth
  3. 自从您开始以来,我建议您python-social-auth以后直接使用django-social-auth is deprecated