2014-03-13 51 views
0

這是我的Django的第一個項目,我安裝Django社會權威性和工作正常,但是當我使用自定義管道註冊進入/登錄錯誤管道Django的社會權威性

使用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() 
+0

你使用的是什麼版本的python和django? 'python --version'和'django-admin.py --version' – broinjc

+0

僅供參考,Django-social-auth現已棄用。謹慎使用它。 –

+0

使用python 2.6 django 1.6.2 –

回答

1

您的代碼中有幾個不正確的細節。

  1. 'social_auth.backends.pipeline.misc.save_status_to_session'應,如果你打算將用戶重定向到另一個視圖/表格(打破了加工後,再繼續吧)
  2. 您的自定義管道使用strategy這是一個參數的前提下使用python-social-auth但不django-social-auth

既然你開始,我會建議直接python-social-authdjango-social-auth is deprecated

+0

嗯,我實現了python-social-auth並按照你的建議修復了代碼,但是我有同樣的問題 –

+0

@LuisAlfredo,將管道設置更新爲默認值http:// psa .matiasaguirre.net/docs/pipeline.html#authentication-pipeline(頂部有一些缺失的條目),檢查默認是否工作,然後將管道功能添加到列表中,如果失敗則進行調試。 – omab