From 8e4ab9f3a947247b122319558da3f75a27a123ab Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 12 Mar 2018 19:39:27 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96?= =?UTF-8?q?token=E7=9A=84=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/users/api.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/users/api.py b/apps/users/api.py index b485a593e..07d708d89 100644 --- a/apps/users/api.py +++ b/apps/users/api.py @@ -180,15 +180,24 @@ class UserConnectionTokenApi(APIView): 'asset': asset_id, 'system_user': system_user_id } - cache.set(token, value, timeout=3600) + cache.set(token, value, timeout=60) return Response({"token": token}, status=201) def get(self, request): token = request.query_params.get('token') + user_only = request.query_params.get('user-only', None) value = cache.get(token, None) - if value: + + if not value: + return Response('', status=404) + + if not user_only: cache.delete(token) - return Response(value) - - + return Response(value) + else: + return Response({'user': value['user']}) + def get_permissions(self): + if self.request.query_params.get('user-only', None): + self.permission_classes = (AllowAny,) + return super().get_permissions()