123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
- @AUTHOR: ASJRD018
- @NAME: AnsjerFormal
- @software: PyCharm
- @DATE: 2019/3/4 16:30
- @Version: python3.6
- @MODIFY DECORD:ansjer dev
- @file: DeviceShare.py
- @Contact: chanjunkai@163.com
- """
- from django.views.generic.base import View
- from Model.models import Device_Info
- from Object.RedisObject import RedisObject
- from Object.ResponseObject import ResponseObject
- from Object.TokenObject import TokenObject
- import time
- from Ansjer.config import SERVER_DOMAIN
- import jwt
- class DeviceShareView(View):
- def get(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- return self.validation(request.GET, operation)
- def post(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- return self.validation(request.POST, operation)
- def validation(self, request_dict, operation):
- response = ResponseObject()
- token = request_dict.get('token', None)
- if token:
- tko = TokenObject(token)
- if tko.code == 0:
- if operation == 'generateTokenUrl':
- return self.do_generate_token_url(tko.userID, request_dict, response)
- else:
- return response.json(414)
- else:
- return response.json(tko.code)
- else:
- return response.json(444, {'param': 'token'})
- def do_generate_token_url(self, userID, request_dict, response):
- UID = request_dict.get('UID', None)
- dvqs = Device_Info.objects.filter(UID=UID, userID_id=userID, isShare=False)
- if dvqs.exists():
- data = {'sharer': userID, 'UID': UID}
- share_token = jwt.encode(data, 'jwt.#^^&', algorithm='HS256')
- share_url = '{SERVER_DOMAIN}deviceShare/confirm?shareToken={shareToken}' \
- .format(SERVER_DOMAIN=SERVER_DOMAIN, shareToken=share_token.decode('utf-8'))
- return response.json(0, {'share_url': share_url})
- else:
- return response.json(173)
- def do_confirm(self, userID, request_dict, response):
- shareToken = request_dict.get('shareToken', None)
- if shareToken is not None:
- data = jwt.decode(shareToken, 'jwt.#^^&', algorithms='HS256')
- sharer = data.get('sharer', None)
- UID = data.get('UID', None)
- dval = Device_Info.objects.filter(userID_id=userID, UID=UID)
- if not dval.exists():
- sharerDvqs = Device_Info.objects.filter(userID_id=sharer, UID=UID)
- if sharerDvqs.exists():
- pass
- else:
- return response.json(173)
- else:
- return response.json(174)
- else:
- return response.json(444, {'param': 'shareToken'})
|