2014-12-28 49 views
2

回到這裏的數據是我的Python代碼EVE無法從Python的EVE API

from eve import Eve 
from eve.auth import BasicAuth 

class MyBasicAuth(BasicAuth): 
    def check_auth(self, username, password, allowed_roles, resource, 
        method): 
     if resource == 'auth': 
      user = app.data.driver.db['user'] 
      user = user.find_one({'email': username,'password':password}) 
      if user: 
       return user 
      else: 
       False 
     else: 
      return True 

app = Eve(auth=MyBasicAuth) 

if __name__ == '__main__': 
    app.run() 

在驗證成功,我返回user對象,但什麼都不會返回。我哪裏錯了。 這裏是settings.py文件

RESOURCE_METHODS = ['GET', 'POST'] 

DOMAIN = { 
    'user': { 
     'schema': { 
      'firstname': { 
       'type': 'string' 
      }, 
      'lastname': { 
       'type': 'string' 
      }, 
      'email': { 
       'type': 'string' 
      }, 
     'password': { 
     'type': 'string' 
     }, 
      'phone': { 
       'type': 'string' 
      } 
     } 
    }, 
    'auth': { 
     'schema': { 
      'username': { 
       'type': 'string' 
       }, 
      'password': { 
       'type':'string' 
       } 
      } 
     } 
} 

回答

1

身份驗證和授權無關與返回的數據。您的MyBasicAuth課程僅應返回TrueFalse以便允許處理或拒絕當前請求。

  1. 您的自定義身份驗證類返回True

  2. user收集在數據庫中有文件(你是:

    假設你的客戶端被擊中user終點,它將如果返回數據不提供datasource,所以Eve默認爲端點作爲數據源名稱)。

而且我不知道爲什麼你如果resource == 'auth'因爲你沒有在你的領域建立一個auth端點測試。

爲了取得領先優勢,您可能需要首先檢查QuickStart,然後Authentication and Authorization,最後再查看RESTful Account Management教程。

+0

嘿..你好,'settings.py'中的錯誤更新爲包含auth端點。我正在嘗試編寫一個Auth API來驗證用戶名和密碼,並在成功驗證時返回用戶詳細信息。由於正在點擊的端點不是'user',所以'auth'可以告訴我如何返回用戶詳細信息。 – iJade