0
今天我試圖讓django活塞和ExtJS工作。我用ExtJS寧靜的例子和活塞的例子來創建一個有點寧靜的webapp。一切工作正常,除了身份驗證。(O)Auth與ExtJS
什麼是使用ExtJS獲得Basic/Digest/OAuth身份驗證的最佳方式? Atm我不確定在哪裏設置用戶名/密碼。
感謝
今天我試圖讓django活塞和ExtJS工作。我用ExtJS寧靜的例子和活塞的例子來創建一個有點寧靜的webapp。一切工作正常,除了身份驗證。(O)Auth與ExtJS
什麼是使用ExtJS獲得Basic/Digest/OAuth身份驗證的最佳方式? Atm我不確定在哪裏設置用戶名/密碼。
感謝
如果你想使用活塞與ExtJS的,我會建議寫一個匿名處理程序,檢查用戶通過標準的權威性登錄。
試試這個:
class AnonymousUserProfileHandler(BaseHandler):
fields = ('title', 'url', 'affiliation')
model = UserProfile
def read(self, request, nickname):
profile = UserProfile.objects.get(nickname=nickname)
if request.user == profile.user:
return profile
class UserProfileHandler(BaseHandler):
anonymous = AnonymousUserProfileHandler
allowed_methods = ('GET')
fields = ('title', 'url', 'affiliation')
model = UserProfile
def read(self, request, nickname):
profile = UserProfile.objects.get(nickname=nickname)
return profile
在這個例子中,當UserProfileHandler被調用時,沒有任何授權,將其委託給匿名處理。匿名處理程序通過通常的request.user模式檢查用戶是否登錄。如果有一個有效的用戶,它將返回他們的配置文件對象。顯然,你會將這個視爲是需要登錄的標記。
重點是:當extJS進行JSON調用時,它將通過通常的cookie發送認證數據。如果您在活塞中使用「匿名」處理程序,但在返回數據之前手動檢查用戶是否已登錄,那麼您實際上使用傳統身份驗證作爲自己的站點。