|
@@ -39,6 +39,8 @@ class UserRelatedView(View):
|
|
|
return self.get_scanning_status(request_dict, response)
|
|
|
elif operation == 'web-login': # 网页登录
|
|
|
return self.web_login(request_dict, response)
|
|
|
+ elif operation == 'pc-login': # pc端登录
|
|
|
+ return self.pc_login(request_dict, response)
|
|
|
elif operation == 'confirm-login': # app确认登录
|
|
|
return self.confirm_login(request_dict, response)
|
|
|
else:
|
|
@@ -54,6 +56,29 @@ class UserRelatedView(View):
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def get_user_info(user_id):
|
|
|
+ """
|
|
|
+ 获取用户信息
|
|
|
+ @param user_id: 用户id
|
|
|
+ @return: response
|
|
|
+ """
|
|
|
+ device_user_qs = Device_User.objects.filter(userID=user_id).values('NickName', 'userIconPath',
|
|
|
+ 'userIconUrl')
|
|
|
+ if not device_user_qs.exists():
|
|
|
+ user_icon_url = ''
|
|
|
+ nick_name = ''
|
|
|
+ else:
|
|
|
+ users = device_user_qs.first()
|
|
|
+ nick_name = users['NickName']
|
|
|
+ user_icon_path = str(users['userIconPath'])
|
|
|
+ if user_icon_path:
|
|
|
+ user_icon_path = user_icon_path.replace('static/', '').replace('\\', '/')
|
|
|
+ user_icon_url = SERVER_DOMAIN + 'account/getAvatar/' + user_icon_path
|
|
|
+ else:
|
|
|
+ user_icon_url = ''
|
|
|
+ return user_icon_url, nick_name
|
|
|
+
|
|
|
@staticmethod
|
|
|
def generate_qr_code(response):
|
|
|
"""
|
|
@@ -65,7 +90,7 @@ class UserRelatedView(View):
|
|
|
redis_obj = RedisObject()
|
|
|
try:
|
|
|
uuid_number = hashlib.md5((str(uuid.uuid1()) + str(nwo_time)).encode('utf-8')).hexdigest()
|
|
|
- flag = redis_obj.set_ex_data(uuid_number, 0, 300)
|
|
|
+ flag = redis_obj.set_ex_data(uuid_number, 0, 300) # redis记录uuid,状态为生成二维码
|
|
|
res = {'type': 'autologin', 'id': uuid_number}
|
|
|
if flag:
|
|
|
return response.json(0, res)
|
|
@@ -92,10 +117,43 @@ class UserRelatedView(View):
|
|
|
status = redis_obj.get_data(uuid_number)
|
|
|
if status is False:
|
|
|
return response.json(119)
|
|
|
- elif status == '0':
|
|
|
- res = {'status': 0} # 未扫码
|
|
|
- else:
|
|
|
+ elif status == '1' or status == '2':
|
|
|
res = {'status': 1} # 已扫码
|
|
|
+ else:
|
|
|
+ res = {'status': 0} # 未扫码
|
|
|
+ return response.json(0, res)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def pc_login(request_dict, response):
|
|
|
+ """
|
|
|
+ pc端登录
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @request_dict serial_number: 序列号
|
|
|
+ @param response: 响应对象
|
|
|
+ @return: response
|
|
|
+ """
|
|
|
+ uuid_number = request_dict.get('uuid', None)
|
|
|
+ if not uuid_number:
|
|
|
+ return response.json(444, {'error param': 'uuid'})
|
|
|
+ try:
|
|
|
+ redis_obj = RedisObject()
|
|
|
+ status = redis_obj.get_data(uuid_number)
|
|
|
+ token = redis_obj.get_data(uuid_number + 'token')
|
|
|
+ if status is False or token is False:
|
|
|
+ return response.json(119)
|
|
|
+ elif status == '2': # 已登录
|
|
|
+ token_obj = TokenObject(token)
|
|
|
+ response.lang = token_obj.lang
|
|
|
+ if token_obj.code != 0:
|
|
|
+ return response.json(token_obj.code)
|
|
|
+ user_id = token_obj.userID
|
|
|
+ user_icon_url, nick_name = UserRelatedView.get_user_info(user_id)
|
|
|
+ res = {'status': 1, 'userIconUrl': user_icon_url, 'nickName': nick_name}
|
|
|
+ else: # 未登录
|
|
|
+ res = {'status': 0}
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
@@ -116,35 +174,24 @@ class UserRelatedView(View):
|
|
|
return response.json(444, {'error param': 'uuid or confirm'})
|
|
|
try:
|
|
|
redis_obj = RedisObject()
|
|
|
- if confirm == '1':
|
|
|
+ if confirm == '1': # 取消登录
|
|
|
redis_obj.del_data(uuid_number)
|
|
|
+ redis_obj.del_data(uuid_number + 'token')
|
|
|
return response.json(0)
|
|
|
- status = redis_obj.get_data(uuid_number)
|
|
|
- if status == '0':
|
|
|
- return response.json(18)
|
|
|
- elif status is False:
|
|
|
+ token = redis_obj.get_data(uuid_number + 'token')
|
|
|
+ ttl = redis_obj.get_ttl(uuid_number)
|
|
|
+ if token is False or ttl == 0:
|
|
|
return response.json(119)
|
|
|
- redis_obj.del_data(uuid_number)
|
|
|
- tko = TokenObject(status, returntpye='pc')
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code != 0:
|
|
|
- return response.json(tko.code)
|
|
|
- user_id = tko.userID
|
|
|
- device_user_qs = Device_User.objects.filter(userID=user_id).values('NickName', 'userIconPath',
|
|
|
- 'userIconUrl')
|
|
|
- if not device_user_qs.exists():
|
|
|
- user_icon_url = ''
|
|
|
- nick_name = ''
|
|
|
- else:
|
|
|
- users = device_user_qs.first()
|
|
|
- nick_name = users['NickName']
|
|
|
- user_icon_path = str(users['userIconPath'])
|
|
|
- if user_icon_path:
|
|
|
- user_icon_path = user_icon_path.replace('static/', '').replace('\\', '/')
|
|
|
- user_icon_url = SERVER_DOMAIN + 'account/getAvatar/' + user_icon_path
|
|
|
- else:
|
|
|
- user_icon_url = ''
|
|
|
- return response.json(0, {'token': status, 'userIconUrl': user_icon_url, 'nickName': nick_name})
|
|
|
+ result = redis_obj.set_ex_data(uuid_number, 2, ttl)
|
|
|
+ if result is False:
|
|
|
+ return response.json(119)
|
|
|
+ token_obj = TokenObject(token)
|
|
|
+ response.lang = token_obj.lang
|
|
|
+ if token_obj.code != 0:
|
|
|
+ return response.json(token_obj.code)
|
|
|
+ user_id = token_obj.userID
|
|
|
+ user_icon_url, nick_name = UserRelatedView.get_user_info(user_id)
|
|
|
+ return response.json(0, {'token': token, 'userIconUrl': user_icon_url, 'nickName': nick_name})
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return response.json(500)
|
|
@@ -165,11 +212,13 @@ class UserRelatedView(View):
|
|
|
redis_obj = RedisObject()
|
|
|
try:
|
|
|
status = redis_obj.get_data(uuid_number)
|
|
|
- if status is False:
|
|
|
+ ttl = redis_obj.get_ttl(uuid_number)
|
|
|
+ if status is False or ttl <= 0:
|
|
|
+ return response.json(119)
|
|
|
+ result1 = redis_obj.set_ex_data(uuid_number, 1, ttl) # 修改uuid状态为已扫码
|
|
|
+ result2 = redis_obj.set_ex_data(uuid_number + 'token', token, ttl)
|
|
|
+ if result1 is False or result2 is False:
|
|
|
return response.json(119)
|
|
|
- flag = redis_obj.set_ex_data(uuid_number, token, 300)
|
|
|
- if flag is False:
|
|
|
- return response.json(309)
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
print(e)
|