瀏覽代碼

[ADD] auth endpoints

Gogs 7 年之前
父節點
當前提交
1fa3c564b6
共有 7 個文件被更改,包括 66 次插入1 次删除
  1. 13 0
      api/resources/group_resource.py
  2. 13 0
      api/resources/permission_resource.py
  3. 13 0
      api/resources/user_resource.py
  4. 6 0
      api/urls.py
  5. 19 1
      api/utils/jwt_token.py
  6. 二進制
      db.sqlite3
  7. 2 0
      odoo_control/settings.py

+ 13 - 0
api/resources/group_resource.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from tastypie.resources import ModelResource
+from tastypie.authorization import Authorization
+from django.contrib.auth.models import Group
+
+'''
+'''
+class GroupResource(ModelResource):
+    class Meta:
+        queryset = Group.objects.all()
+        authorization = Authorization()
+        always_return_data = True

+ 13 - 0
api/resources/permission_resource.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from tastypie.resources import ModelResource
+from tastypie.authorization import Authorization
+from django.contrib.auth.models import Permission
+
+'''
+'''
+class PermissionResource(ModelResource):
+    class Meta:
+        queryset = Permission.objects.all()
+        authorization = Authorization()
+        always_return_data = True

+ 13 - 0
api/resources/user_resource.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from tastypie.resources import ModelResource
+from tastypie.authorization import Authorization
+from django.contrib.auth.models import User
+
+'''
+'''
+class UserResource(ModelResource):
+    class Meta:
+        queryset = User.objects.all()
+        authorization = Authorization()
+        always_return_data = True

+ 6 - 0
api/urls.py

@@ -3,9 +3,15 @@ from __future__ import unicode_literals
 from django.conf.urls import url
 from tastypie.api import Api
 
+from api.resources.user_resource import UserResource
+from api.resources.permission_resource import PermissionResource
+from api.resources.group_resource import GroupResource
 from api.resources.request_resource import RequestResource
 from api.resources.task_resource import TaskResource
 
 v1_api = Api(api_name='v1')
+v1_api.register(UserResource())
+v1_api.register(PermissionResource())
+v1_api.register(GroupResource())
 v1_api.register(RequestResource())
 v1_api.register(TaskResource())

+ 19 - 1
api/utils/jwt_token.py

@@ -1,7 +1,25 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from django.conf import settings
+from django.contrib.auth import authenticate
+import jwt
+
 '''
 '''
 def create_token(self, username, password):
-    pass
+    user = authenticate(username=username, password=password)
+
+    if user is None:
+        return user
+
+    payload = {
+        'uid': user.id,
+        'password': password
+    }
+
+    print(user)
+
+
 
 '''
 '''

二進制
db.sqlite3


+ 2 - 0
odoo_control/settings.py

@@ -123,4 +123,6 @@ USE_TZ = True
 
 STATIC_URL = '/static/'
 
+JWT_SECRET_KEY = '123456789'
+
 PLAYBOOKS_PATH = '/home/robert/workspace/playbooks'