2009-12-15 66 views
2

我有一個django服務器應用程序,使用JSON與gwt前端進行通信。我想嚮應用介紹用戶身份驗證,並已開始合併the framework provided by django。在這一點上,我已經建立了服務器,以便在必要時使用用戶認證表單(使用上面鏈接中描述的@login_required裝飾器方案),但我不確定在GWT中如何處理。django用戶身份驗證+ gwt

如果你正在使用GWT和Django並且已經實現了用戶身份驗證,那麼聽聽你如何設置東西真是太好了。

謝謝。

+0

你有工作嗎? – 2010-05-06 21:54:19

回答

0

我從來沒有使用過Django,但你可能會設置當需要登錄時會返回什麼。

例如,您可以返回一條消息,以便客戶端可以使用身份驗證表單提示用戶。當然,每次調用都需要考慮這種情況,但是您可以創建一個抽象請求類來執行此操作。

1

自動測試項目使用gwt和django組合。看看http://autotest.kernel.org/browser/trunk/frontend的源代碼。具體來說,我會修改http://autotest.kernel.org/browser/trunk/frontend/afe/json_rpc/serviceHandler.py並添加下面的內容(這將過濾登錄,註銷和is_logged_in和所有其他功能,它會調用request.user.is_authenticated(),以確保所有其他json rpc受保護)

def invokeServiceEndpoint(self, meth, request, response, args): 
    if meth.func_name == "login" or meth.func_name == "logout" or meth.func_name == "is_loggedin": 
    return meth(request, *args) 
    else: 
    if request.user.is_authenticated(): 
     return meth(request.user, *args) 
    else: 
     from studio.rpc_exceptions import AccessDeniedException 
     raise AccessDeniedException()