我想創建登錄資源,但我不能把握怎麼辦呢:(Tastypie登錄
我有我的UserResource,我認爲這將是最好用LoginResource作爲登錄方法。
class UserResource(ModelResource):
foreign_key = ForeignKey(ForeignResource, 'foreign_key', null=True)
...
class Meta:
queryset = User.objects.all()
allowed_methods = ['post']
resource_name = 'user'
authentication = ApiKeyAuthentication()
authorization = Authorization()
def obj_create(self, bundle, **kwargs):
try:
bundle = super(UserResource, self).obj_create(bundle, **kwargs)
bundle.obj.set_password(bundle.data.get('password'))
bundle.obj.save()
except IntegrityError:
raise BadRequest(_("A user with that username already exists."))
return bundle
所以,我應該怎麼辦LoginResource實現,這是多遠,我已經得到了:)
class LoginResource(ModelResource):
pass
我的願望是發送(POST/GET)/ V1 /登錄/用戶名和密碼然後如果登錄成功返回用戶對象,如果我有GET/v1/user/1 /。
在此先感謝!
雖然你可以這樣做,但對我而言,僅僅使用Apikey athentication和授權類來限制對記錄的訪問會更好。 – airtonix 2013-04-27 17:49:11