authentication - Django TastyPie User Login Returns 501 Not Implemented -


i trying enable user creation , login/logout through ios app. have userresource created , registered. have written login function within resource:

class userresource(modelresource): class meta:     queryset = user.objects.all()     fields = ['username', 'email']     serializer = prettyjsonserializer()     authorization = authorization()   def login(self, request, **kwargs):     self.method_check(request, allowed=['post'])      username = request.post['username']     password = request.post['password']      user = authenticate(username = username, password = password)      if user:         if user.is_active:             login(request, user)             return self.create_response(request, {'success' : true})         else:             return self.create_response(request, {'success' : false, 'reason' : 'disabled'}, httpforbidden)     else:         return self.create_response(request, {'success' : false, 'reason' : 'incorrect'}, httpunauthorized)  def logout(self, request, **kwargs):     pass 

when try

 curl -v -h "content-type: application/json" -x post --data '{"username":"username", "password":"password"}' xxx.xxx.xx.xx:8000/api/v1/user/login/?format=json 

it returns:

* connect() xxx.xxx.xx.xx port 8000 (#0) *   trying xxx.xxx.xx.xx... * connected * connected xxx.xxx.xx.xx (xxx.xxx.xx.xx) port 8000 (#0) > post /api/v1/user/login/?format=json http/1.1 > user-agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 openssl/0.9.8x zlib/1.2.5 > host: xxx.xxx.xx.xx > accept: */* > content-type: application/json > content-length: 55 >  * upload sent off: 55 out of 55 bytes < http/1.1 501 not implemented < server: gunicorn/17.5 < date: wed, 31 jul 2013 20:59:42 gmt < connection: close < transfer-encoding: chunked < vary: accept < content-type: text/html; charset=utf-8 <  * closing connection #0 

as turns out accessing username , password through request.post incorrect. after digging found did trick.

    data = self.deserialize(request, request.body, format = request.meta.get('content_type', 'application/json'))      username = data.get('email', '')     password = data.get('password', '') 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -