|
@@ -7,11 +7,12 @@
|
|
|
@Software: PyCharm
|
|
|
"""
|
|
|
import datetime
|
|
|
-import random
|
|
|
import time
|
|
|
|
|
|
+from django.db import transaction
|
|
|
+
|
|
|
from Controller.CheckUserData import RandomStr
|
|
|
-from Model.models import Device_User, Device_Info, DeviceSuperPassword
|
|
|
+from Model.models import Device_User, Device_Info, DeviceSuperPassword, SysMsgModel
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
@@ -42,12 +43,12 @@ class AppAccoutView(View):
|
|
|
return response.json(token.code)
|
|
|
if operation == 'getAuthorizationCode': # 获取用户请求/生成授权码
|
|
|
return self.getAuthorizationCode(request_dict, response, userID)
|
|
|
- if operation == 'verifyTheVerificationCode': # 效验验证码
|
|
|
- return self.verifyTheVerificationCode(request_dict, response)
|
|
|
- if operation == 'customerServiceManagement': # 客服管理
|
|
|
+ if operation == 'customerServiceManagement': # 编辑超级密码请求表
|
|
|
return self.customerServiceManagement(request_dict, response)
|
|
|
if operation == 'getDeviceSuperPassword': # 查询超级密码请求表
|
|
|
return self.getDeviceSuperPassword(request_dict, response)
|
|
|
+ if operation == 'verifyTheVerificationCode': # 检验验证码
|
|
|
+ return self.verifyTheVerificationCode(request_dict, response, userID)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
@@ -69,6 +70,7 @@ class AppAccoutView(View):
|
|
|
purchase_channel = request_dict.get('purchase_channel', None)
|
|
|
orderID = request_dict.get('orderID', None)
|
|
|
buyTime = request_dict.get('buyTime', None)
|
|
|
+ lang = request_dict.get('lang', 'en')
|
|
|
try:
|
|
|
now = int(time.time())
|
|
|
addTime = now
|
|
@@ -79,62 +81,118 @@ class AppAccoutView(View):
|
|
|
buyTime = datetime.datetime.strptime(buyTime, '%Y-%m-%d')
|
|
|
buyTime = CommonService.str_to_timestamp(str_time=str(buyTime))
|
|
|
DeviceSuperPassword.objects.create(uid=uid, orderID=orderID, describe=describe,
|
|
|
- purchase_channel=purchase_channel, addTime=addTime, userID=userID,
|
|
|
- buyTime=buyTime, status=0)
|
|
|
+ purchase_channel=purchase_channel, addTime=addTime, userID_id=userID,
|
|
|
+ buyTime=buyTime, status=0, lang=lang)
|
|
|
# 验证码生成
|
|
|
super_code = RandomStr(6, True)
|
|
|
- super_password_id = "super_password_%s" % super_code
|
|
|
- redisObj = RedisObject(db=6)
|
|
|
+ super_password_id = "super_password_%s" % userID
|
|
|
+ redisObj = RedisObject()
|
|
|
redisObj.set_data(key=super_password_id, val=super_code, expire=86400)
|
|
|
- authcode = CommonService.encode_data(super_code)
|
|
|
|
|
|
- return response.json(0, {'authcode': authcode})
|
|
|
+ return response.json(0)
|
|
|
except Exception as e:
|
|
|
- print('获取验证码异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ print('生成验证码异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
- def verifyTheVerificationCode(self, request_dict, response):
|
|
|
- verificationCode = request_dict.get('verificationCode', None)
|
|
|
- authcode = request_dict.get('authcode', None)
|
|
|
-
|
|
|
- if verificationCode and authcode:
|
|
|
-
|
|
|
- authcode = CommonService.decode_data(authcode)
|
|
|
- super_password_id = 'super_password_' + verificationCode
|
|
|
- redisObj = RedisObject(db=6)
|
|
|
- # redis里面的验证码
|
|
|
- redis_image_code = redisObj.get_data(key=super_password_id)
|
|
|
- # 验证用户输入的验证码和redis中的验证码
|
|
|
- if redis_image_code is False or authcode.lower() != redis_image_code.lower():
|
|
|
- return response.json(121)
|
|
|
- else:
|
|
|
- return response.json(0)
|
|
|
- else:
|
|
|
- return response.json(444)
|
|
|
+ # def storeTheVerificationCode(self, userID, uid, lang, authcode, status, hint, response):
|
|
|
+ # now = int(time.time())
|
|
|
+ # try:
|
|
|
+ # with transaction.atomic():
|
|
|
+ # if authcode and uid and userID:
|
|
|
+ # device_super_password_qs = DeviceSuperPassword.objects.filter(uid=uid, userID=userID)
|
|
|
+ # if not device_super_password_qs.exists():
|
|
|
+ # return response.json(173)
|
|
|
+ # authcode = CommonService.decode_data(authcode)
|
|
|
+ # if status == 1:
|
|
|
+ # if lang == 'en':
|
|
|
+ # msg = "Your authorization code is " + authcode + ",valid within 24 hours"
|
|
|
+ # else:
|
|
|
+ # msg = "您的授权代码:" + authcode + ",24小时内有效"
|
|
|
+ # code = CommonService.encode_data(authcode)
|
|
|
+ # SysMsgModel.objects.create(userID_id=userID, msg=msg, addTime=now, updTime=now, uid=uid,
|
|
|
+ # eventType=2, code=code)
|
|
|
+ # return response.json(0)
|
|
|
+ # if status == 0 and len(hint) > 1:
|
|
|
+ # msg = hint
|
|
|
+ # SysMsgModel.objects.create(userID_id=userID, msg=msg, addTime=now, updTime=now, uid=uid,
|
|
|
+ # eventType=2)
|
|
|
+ # return response.json(0)
|
|
|
+ # return response.json(444)
|
|
|
+ # except Exception as e:
|
|
|
+ # print('验证码保存异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ # return response.json(500, repr(e))
|
|
|
|
|
|
def customerServiceManagement(self, request_dict, response):
|
|
|
+ """
|
|
|
+ @param request_dict:请求参数
|
|
|
+ @param response:响应对象
|
|
|
+ @param hint:提示内容
|
|
|
+ @return:
|
|
|
+ """
|
|
|
userID = request_dict.get('userID')
|
|
|
uid = request_dict.get('uid', None)
|
|
|
status = request_dict.get('status', None)
|
|
|
hint = request_dict.get('hint', None)
|
|
|
+ lang = request_dict.get('lang', 'en')
|
|
|
if not all({uid, userID}):
|
|
|
return response.json(444)
|
|
|
+ now = int(time.time())
|
|
|
try:
|
|
|
- device_super_password_qs = DeviceSuperPassword.objects.filter(uid=uid, userID=userID)
|
|
|
- if not device_super_password_qs.exists():
|
|
|
- return response.json(173)
|
|
|
- status = int(status)
|
|
|
- if status == 1:
|
|
|
- device_super_password_qs.update(status=status)
|
|
|
- return response.json(0)
|
|
|
- else:
|
|
|
- device_super_password_qs.update(status=status, hint=hint)
|
|
|
- return response.json(0)
|
|
|
+ with transaction.atomic():
|
|
|
+ device_super_password_qs = DeviceSuperPassword.objects.filter(uid=uid, userID=userID)
|
|
|
+ if not device_super_password_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ status = int(status)
|
|
|
+ authcode = ''
|
|
|
+ if status == 1:
|
|
|
+ device_super_password_qs.update(status=status)
|
|
|
+ super_password_id = 'super_password_' + userID
|
|
|
+ redisObj = RedisObject()
|
|
|
+ # redis里面的验证码
|
|
|
+ redis_super_code = redisObj.get_data(key=super_password_id)
|
|
|
+ # 验证用户输入的验证码和redis中的验证码
|
|
|
+ if redis_super_code is False:
|
|
|
+ return response.json(120)
|
|
|
+ authcode = CommonService.encode_data(redis_super_code)
|
|
|
+ if status == 0:
|
|
|
+ device_super_password_qs.update(status=status, hint=hint)
|
|
|
+ super_password_id = 'super_password_' + userID
|
|
|
+ redisObj = RedisObject()
|
|
|
+ # redis里面的验证码
|
|
|
+ redis_super_code = redisObj.get_data(key=super_password_id)
|
|
|
+ # 验证用户输入的验证码和redis中的验证码
|
|
|
+ if redis_super_code is False:
|
|
|
+ return response.json(120)
|
|
|
+ authcode = CommonService.encode_data(redis_super_code)
|
|
|
+ device_super_password_qs = DeviceSuperPassword.objects.filter(uid=uid, userID=userID)
|
|
|
+ if not device_super_password_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ authcode = CommonService.decode_data(authcode)
|
|
|
+ if status == 1:
|
|
|
+ if lang == 'en':
|
|
|
+ msg = "Your authorization code is " + authcode + ",valid within 24 hours"
|
|
|
+ else:
|
|
|
+ msg = "您的授权代码:" + authcode + ",24小时内有效"
|
|
|
+ code = CommonService.encode_data(authcode)
|
|
|
+ SysMsgModel.objects.create(userID_id=userID, msg=msg, addTime=now, updTime=now, uid=uid,
|
|
|
+ eventType=2, code=code)
|
|
|
+ return response.json(0)
|
|
|
+ if status == 0 and len(hint) > 1:
|
|
|
+ msg = hint
|
|
|
+ SysMsgModel.objects.create(userID_id=userID, msg=msg, addTime=now, updTime=now, uid=uid,
|
|
|
+ eventType=2)
|
|
|
+ return response.json(0)
|
|
|
+ return response.json(177)
|
|
|
except Exception as e:
|
|
|
print('修改状态异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
def getDeviceSuperPassword(self, request_dict, response):
|
|
|
+ """
|
|
|
+ @param request_dict:请求参数
|
|
|
+ @param response:响应对象
|
|
|
+ @return:
|
|
|
+ """
|
|
|
pageNo = request_dict.get('pageNo', None)
|
|
|
pageSize = request_dict.get('pageSize', None)
|
|
|
status = request_dict.get('status', None)
|
|
@@ -164,10 +222,34 @@ class AppAccoutView(View):
|
|
|
'addTime',
|
|
|
'status',
|
|
|
'buyTime',
|
|
|
- 'hint')
|
|
|
+ 'hint',
|
|
|
+ 'lang')
|
|
|
device_super_password_qs = device_super_password_qs.order_by('-addTime')[
|
|
|
(page - 1) * line:page * line]
|
|
|
return response.json(0, {'list': list(device_super_password_qs), 'count': count})
|
|
|
except Exception as e:
|
|
|
print('查询异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return response.json(500, repr(e))
|
|
|
+
|
|
|
+ def verifyTheVerificationCode(self, request_dict, response, userID):
|
|
|
+ """
|
|
|
+ @czVccccccc request_dict:请求参数
|
|
|
+ @param response:响应对象
|
|
|
+ @param userID:用户ID
|
|
|
+ @param authcode:验证码
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ authcode = request_dict.get('authcode', None)
|
|
|
+ if authcode:
|
|
|
+ authcode = CommonService.decode_data(authcode)
|
|
|
+ super_password_id = 'super_password_' + userID
|
|
|
+ redisObj = RedisObject()
|
|
|
+ # redis里面的验证码
|
|
|
+ redis_image_code = redisObj.get_data(key=super_password_id)
|
|
|
+ # 验证用户输入的验证码和redis中的验证码
|
|
|
+ if redis_image_code is False or authcode.lower() != redis_image_code.lower():
|
|
|
+ return response.json(121)
|
|
|
+ else:
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(444)
|