Parcourir la source

[FIX] jwt logger

Gogs il y a 7 ans
Parent
commit
0bae94b1cf
1 fichiers modifiés avec 11 ajouts et 1 suppressions
  1. 11 1
      api/resources/jwt_resource.py

+ 11 - 1
api/resources/jwt_resource.py

@@ -6,6 +6,10 @@ from tastypie.resources import Resource
 from tastypie.utils import trailing_slash
 from tastypie.exceptions import ImmediateHttpResponse
 from api.utils import jwt_token
+from api.utils.logger import (
+    info,
+    warning
+)
 import simplejson as json
 
 '''
@@ -30,22 +34,28 @@ class JWTResource(Resource):
 
         # Check content type
         if request.content_type != 'application/json':
+            warning('request is not json')
             raise ImmediateHttpResponse(response=http.HttpUnauthorized())
 
         # Check body
         if not request.body:
-           raise ImmediateHttpResponse(response=http.HttpUnauthorized())
+            warning('request body not exists')
+            raise ImmediateHttpResponse(response=http.HttpUnauthorized())
 
         # Check required parameters
         body = json.loads(request.body)
         if 'username' not in body or 'password' not in body:
+            warning('username or password not provided')
             raise ImmediateHttpResponse(response=http.HttpUnauthorized())
 
         # Check user
         token = jwt_token.create_token(body['username'], body['password'])
         if not token:
+            warning('empty token')
             raise ImmediateHttpResponse(response=http.HttpUnauthorized())
 
+        info('%s authenticated' % body['username'])
+
         bundle = self.build_bundle(obj={
             'token': token,
             'username': body['username']