|
@@ -14,6 +14,9 @@
|
|
import datetime
|
|
import datetime
|
|
import traceback
|
|
import traceback
|
|
import time
|
|
import time
|
|
|
|
+
|
|
|
|
+import jwt
|
|
|
|
+import simplejson
|
|
import simplejson as json
|
|
import simplejson as json
|
|
import requests
|
|
import requests
|
|
from django.contrib.auth.hashers import make_password, check_password # 对密码加密模块
|
|
from django.contrib.auth.hashers import make_password, check_password # 对密码加密模块
|
|
@@ -23,11 +26,13 @@ from django.utils.decorators import method_decorator
|
|
from django.utils.timezone import utc
|
|
from django.utils.timezone import utc
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.generic import TemplateView
|
|
from django.views.generic import TemplateView
|
|
|
|
+from jwt.algorithms import RSAAlgorithm
|
|
from ratelimit.decorators import ratelimit
|
|
from ratelimit.decorators import ratelimit
|
|
|
|
|
|
from Ansjer.config import AuthCode_Expire, SERVER_DOMAIN, APNS_CONFIG, JPUSH_CONFIG, FCM_CONFIG, TUTK_PUSH_DOMAIN
|
|
from Ansjer.config import AuthCode_Expire, SERVER_DOMAIN, APNS_CONFIG, JPUSH_CONFIG, FCM_CONFIG, TUTK_PUSH_DOMAIN
|
|
from Controller.CheckUserData import DataValid, date_handler, RandomStr
|
|
from Controller.CheckUserData import DataValid, date_handler, RandomStr
|
|
-from Model.models import Device_User, Role, UidPushModel, UserOauth2Model, UserExModel, Device_Info,UidSetModel
|
|
|
|
|
|
+from Model.models import Device_User, Role, UidPushModel, UserOauth2Model, UserExModel, Device_Info, UidSetModel, \
|
|
|
|
+ UserAppFrequencyModel
|
|
from Object.AWS.SesClassObject import SesClassObject
|
|
from Object.AWS.SesClassObject import SesClassObject
|
|
from Object.AliSmsObject import AliSmsObject
|
|
from Object.AliSmsObject import AliSmsObject
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
@@ -50,7 +55,7 @@ class authCodeView(TemplateView):
|
|
|
|
|
|
@method_decorator(csrf_exempt)
|
|
@method_decorator(csrf_exempt)
|
|
def dispatch(self, *args, **kwargs):
|
|
def dispatch(self, *args, **kwargs):
|
|
- # testtest11111111111111
|
|
|
|
|
|
+ # testtest11111111111111
|
|
return super(authCodeView, self).dispatch(*args, **kwargs)
|
|
return super(authCodeView, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
@ratelimit(key='ip', rate='2/m')
|
|
@ratelimit(key='ip', rate='2/m')
|
|
@@ -440,7 +445,6 @@ class v3ChangePwdView(TemplateView):
|
|
return response.json(177)
|
|
return response.json(177)
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
class ForgetPwdView(TemplateView):
|
|
class ForgetPwdView(TemplateView):
|
|
'''
|
|
'''
|
|
忘记密码
|
|
忘记密码
|
|
@@ -972,7 +976,6 @@ class v2registerView(TemplateView):
|
|
return self.do_login(email_qs, response)
|
|
return self.do_login(email_qs, response)
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
# 验证码注册v3
|
|
# 验证码注册v3
|
|
class v3registerView(TemplateView):
|
|
class v3registerView(TemplateView):
|
|
@method_decorator(csrf_exempt)
|
|
@method_decorator(csrf_exempt)
|
|
@@ -1148,7 +1151,6 @@ class v3registerView(TemplateView):
|
|
return self.do_login(email_qs, response)
|
|
return self.do_login(email_qs, response)
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
# 重置密码
|
|
# 重置密码
|
|
# 忘记密码获取验证码v2
|
|
# 忘记密码获取验证码v2
|
|
class v2forgetPwdCodeView(TemplateView):
|
|
class v2forgetPwdCodeView(TemplateView):
|
|
@@ -1414,7 +1416,6 @@ class v2resetPwdByCodeView(TemplateView):
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
# 忘记密码v3
|
|
# 忘记密码v3
|
|
class v3resetPwdByCodeView(TemplateView):
|
|
class v3resetPwdByCodeView(TemplateView):
|
|
@method_decorator(csrf_exempt)
|
|
@method_decorator(csrf_exempt)
|
|
@@ -1572,7 +1573,6 @@ class v3resetPwdByCodeView(TemplateView):
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
# 登录
|
|
# 登录
|
|
class v2LoginView(TemplateView):
|
|
class v2LoginView(TemplateView):
|
|
@method_decorator(csrf_exempt) # @csrf_exempt
|
|
@method_decorator(csrf_exempt) # @csrf_exempt
|
|
@@ -1672,7 +1672,7 @@ class v2LoginView(TemplateView):
|
|
class v3LoginView(TemplateView):
|
|
class v3LoginView(TemplateView):
|
|
@method_decorator(csrf_exempt) # @csrf_exempt
|
|
@method_decorator(csrf_exempt) # @csrf_exempt
|
|
def dispatch(self, *args, **kwargs):
|
|
def dispatch(self, *args, **kwargs):
|
|
- #chong
|
|
|
|
|
|
+ # chong
|
|
return super(v3LoginView, self).dispatch(*args, **kwargs)
|
|
return super(v3LoginView, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
@ratelimit(key='ip', rate='5/m')
|
|
@ratelimit(key='ip', rate='5/m')
|
|
@@ -1714,13 +1714,13 @@ class v3LoginView(TemplateView):
|
|
password = password.decode('utf-8')
|
|
password = password.decode('utf-8')
|
|
# 截去第一位,最后一位
|
|
# 截去第一位,最后一位
|
|
password = password[1:-1]
|
|
password = password[1:-1]
|
|
- if i==2:
|
|
|
|
|
|
+ if i == 2:
|
|
# 第2次先解密
|
|
# 第2次先解密
|
|
password = base64.b64decode(password)
|
|
password = base64.b64decode(password)
|
|
password = password.decode('utf-8')
|
|
password = password.decode('utf-8')
|
|
# 去前2位,后2位
|
|
# 去前2位,后2位
|
|
password = password[2:-2]
|
|
password = password[2:-2]
|
|
- if i==3:
|
|
|
|
|
|
+ if i == 3:
|
|
# 第3次先解密
|
|
# 第3次先解密
|
|
password = base64.b64decode(password)
|
|
password = base64.b64decode(password)
|
|
password = password.decode('utf-8')
|
|
password = password.decode('utf-8')
|
|
@@ -1758,13 +1758,18 @@ class v3LoginView(TemplateView):
|
|
# users = user_qs.values('role__rid', 'role__roleName', 'userID', 'role', 'NickName', 'username', 'userEmail',
|
|
# users = user_qs.values('role__rid', 'role__roleName', 'userID', 'role', 'NickName', 'username', 'userEmail',
|
|
# 'phone', 'password', 'userIconPath', 'user_isValid', 'is_active')[0]
|
|
# 'phone', 'password', 'userIconPath', 'user_isValid', 'is_active')[0]
|
|
users = user_qs.values('role__rid', 'role__roleName', 'userID', 'NickName', 'username', 'userEmail',
|
|
users = user_qs.values('role__rid', 'role__roleName', 'userID', 'NickName', 'username', 'userEmail',
|
|
- 'phone', 'password', 'userIconPath')[0]
|
|
|
|
|
|
+ 'phone', 'password', 'userIconPath', 'fingerprint_enable', 'fingerprint_key')[0]
|
|
if not check_password(password, users['password']):
|
|
if not check_password(password, users['password']):
|
|
return response.json(111)
|
|
return response.json(111)
|
|
userID = users['userID']
|
|
userID = users['userID']
|
|
tko = TokenObject()
|
|
tko = TokenObject()
|
|
res = tko.generate(
|
|
res = tko.generate(
|
|
data={'userID': userID, 'lang': response.lang, 'user': users['username'], 'm_code': '123413243214'})
|
|
data={'userID': userID, 'lang': response.lang, 'user': users['username'], 'm_code': '123413243214'})
|
|
|
|
+ oauth_qs = UserOauth2Model.objects.filter(userID__userID=userID)
|
|
|
|
+ auth_type = 0
|
|
|
|
+ if oauth_qs.exists():
|
|
|
|
+ auth_type = oauth_qs[0].authType
|
|
|
|
+
|
|
if tko.code == 0:
|
|
if tko.code == 0:
|
|
now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
|
|
now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
|
|
user_qs.update(last_login=now_time, language=response.lang)
|
|
user_qs.update(last_login=now_time, language=response.lang)
|
|
@@ -1783,6 +1788,9 @@ class v3LoginView(TemplateView):
|
|
res['username'] = users['username'] if users['username'] is not None else ''
|
|
res['username'] = users['username'] if users['username'] is not None else ''
|
|
res['userEmail'] = users['userEmail'] if users['userEmail'] is not None else ''
|
|
res['userEmail'] = users['userEmail'] if users['userEmail'] is not None else ''
|
|
res['phone'] = users['phone'] if users['phone'] is not None else ''
|
|
res['phone'] = users['phone'] if users['phone'] is not None else ''
|
|
|
|
+ # res['fingerprint_enable'] = users['fingerprint_enable']
|
|
|
|
+ # res['fingerprint_key'] = CommonService.encode_data(content=users['fingerprint_key'], start=2)
|
|
|
|
+ res['authType'] = auth_type
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
else:
|
|
else:
|
|
return response.json(tko.code)
|
|
return response.json(tko.code)
|
|
@@ -1819,7 +1827,7 @@ class InitInfoView(View):
|
|
tz = request_dict.get('tz', '0')
|
|
tz = request_dict.get('tz', '0')
|
|
lang = request_dict.get('lang', '') # 语言区域
|
|
lang = request_dict.get('lang', '') # 语言区域
|
|
now_time = int(time.time())
|
|
now_time = int(time.time())
|
|
- if all([token_val, push_type, appBundleId,userID]):
|
|
|
|
|
|
+ if all([token_val, push_type, appBundleId, userID]):
|
|
push_type = int(push_type)
|
|
push_type = int(push_type)
|
|
if push_type == 0:
|
|
if push_type == 0:
|
|
if appBundleId not in APNS_CONFIG.keys():
|
|
if appBundleId not in APNS_CONFIG.keys():
|
|
@@ -1926,7 +1934,7 @@ class verifyAuthcode(TemplateView):
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|
|
|
|
|
|
-# 获取验证码
|
|
|
|
|
|
+# 微信登录
|
|
class wxAuthSignView(TemplateView):
|
|
class wxAuthSignView(TemplateView):
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
def post(self, request, *args, **kwargs):
|
|
@@ -1958,6 +1966,7 @@ class wxAuthSignView(TemplateView):
|
|
'com.ansjer.loocamccloud': {'appid': 'wx9f6d6ce63f85b367',
|
|
'com.ansjer.loocamccloud': {'appid': 'wx9f6d6ce63f85b367',
|
|
'secret': 'fe495884cd24637f1ae516c7f53d1b97', },
|
|
'secret': 'fe495884cd24637f1ae516c7f53d1b97', },
|
|
'com.ansjer.zccloud': {'appid': 'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
'com.ansjer.zccloud': {'appid': 'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
|
|
+ 'com.ansjer.customizede': {'appid': 'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
# ios
|
|
# ios
|
|
'com.ansjer.zccloud_ab': {'appid': 'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
'com.ansjer.zccloud_ab': {'appid': 'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
# android
|
|
# android
|
|
@@ -2031,6 +2040,12 @@ class wxAuthSignView(TemplateView):
|
|
res['userEmail'] = user_list[0]["userEmail"] if user_list[0]["userEmail"] is not None else ''
|
|
res['userEmail'] = user_list[0]["userEmail"] if user_list[0]["userEmail"] is not None else ''
|
|
res['phone'] = user_list[0]["phone"] if user_list[0]["phone"] is not None else ''
|
|
res['phone'] = user_list[0]["phone"] if user_list[0]["phone"] is not None else ''
|
|
print(res)
|
|
print(res)
|
|
|
|
+ # 添加用户登录类型
|
|
|
|
+ oauth_qs = UserOauth2Model.objects.filter(userID__userID=userID)
|
|
|
|
+ auth_type = 0
|
|
|
|
+ if oauth_qs.exists():
|
|
|
|
+ auth_type = oauth_qs[0].authType
|
|
|
|
+ res['authType'] = auth_type
|
|
user_qs.update(last_login=now_time, online=True)
|
|
user_qs.update(last_login=now_time, online=True)
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
|
|
|
|
@@ -2100,9 +2115,11 @@ class wxPerfectView(TemplateView):
|
|
'com.ansjer.loocamccloud': {'appid': 'wx9f6d6ce63f85b367',
|
|
'com.ansjer.loocamccloud': {'appid': 'wx9f6d6ce63f85b367',
|
|
'secret': 'fe495884cd24637f1ae516c7f53d1b97', },
|
|
'secret': 'fe495884cd24637f1ae516c7f53d1b97', },
|
|
'com.ansjer.zccloud': {'appid': 'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
'com.ansjer.zccloud': {'appid': 'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
|
|
+ 'com.ansjer.customizede': {'appid':'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
# android
|
|
# android
|
|
'com.ansjer.zccloud_ab': {'appid': 'wx2a9f5ef9baf2760f',
|
|
'com.ansjer.zccloud_ab': {'appid': 'wx2a9f5ef9baf2760f',
|
|
'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
|
|
+
|
|
}
|
|
}
|
|
if appBundleID in app_config.keys():
|
|
if appBundleID in app_config.keys():
|
|
appid = app_config[appBundleID]['appid']
|
|
appid = app_config[appBundleID]['appid']
|
|
@@ -2410,13 +2427,17 @@ class OauthPerfectView(TemplateView):
|
|
password = request_dict.get('password', None)
|
|
password = request_dict.get('password', None)
|
|
authcode = request_dict.get('authcode', None)
|
|
authcode = request_dict.get('authcode', None)
|
|
token = request_dict.get('token', None)
|
|
token = request_dict.get('token', None)
|
|
- print(token)
|
|
|
|
token = request_dict.get('token')
|
|
token = request_dict.get('token')
|
|
tko = TokenObject(token)
|
|
tko = TokenObject(token)
|
|
if password is None or authcode is None:
|
|
if password is None or authcode is None:
|
|
return response.json(444, 'password,authcode')
|
|
return response.json(444, 'password,authcode')
|
|
- authcode = authcode.strip()
|
|
|
|
- password = password.strip()
|
|
|
|
|
|
+ authcode = CommonService.decode_data(authcode.strip())
|
|
|
|
+ if authcode is None:
|
|
|
|
+ return response.json(444, 'password,authcode')
|
|
|
|
+
|
|
|
|
+ password = CommonService.decode_data(password.strip())
|
|
|
|
+ if password is None:
|
|
|
|
+ return response.json(444, 'password,authcode')
|
|
if phone is not None:
|
|
if phone is not None:
|
|
phone = phone.strip()
|
|
phone = phone.strip()
|
|
return self.do_phone(tko, phone, authcode, password, response)
|
|
return self.do_phone(tko, phone, authcode, password, response)
|
|
@@ -2580,11 +2601,12 @@ class alexaAuthView(TemplateView):
|
|
# uid_arr.append({'uid': uid_q['UID'], 'nick': uid_q['NickName'], 'password': uid_q['View_Password']})
|
|
# uid_arr.append({'uid': uid_q['UID'], 'nick': uid_q['NickName'], 'password': uid_q['View_Password']})
|
|
res = {
|
|
res = {
|
|
'userID': userID,
|
|
'userID': userID,
|
|
- # 'uid_arr': uid_arr
|
|
|
|
|
|
+ # 'uid_arr': uid_arr
|
|
}
|
|
}
|
|
- return response.json(0,res)
|
|
|
|
|
|
+ return response.json(0, res)
|
|
# return response.json(0, res)
|
|
# return response.json(0, res)
|
|
|
|
|
|
|
|
+
|
|
class alexaUidView(TemplateView):
|
|
class alexaUidView(TemplateView):
|
|
def post(self, request, *args, **kwargs):
|
|
def post(self, request, *args, **kwargs):
|
|
request.encoding = 'utf-8'
|
|
request.encoding = 'utf-8'
|
|
@@ -2609,11 +2631,11 @@ class alexaUidView(TemplateView):
|
|
uid_list = []
|
|
uid_list = []
|
|
for uid_q in uid_qs:
|
|
for uid_q in uid_qs:
|
|
uid_list.append(uid_q['UID'])
|
|
uid_list.append(uid_q['UID'])
|
|
- uid_arr.append({'uid': uid_q['UID'], 'nick': uid_q['NickName'], 'password': uid_q['View_Password'],})
|
|
|
|
|
|
+ uid_arr.append({'uid': uid_q['UID'], 'nick': uid_q['NickName'], 'password': uid_q['View_Password'], })
|
|
res = {
|
|
res = {
|
|
'uid_arr': uid_arr
|
|
'uid_arr': uid_arr
|
|
}
|
|
}
|
|
- return response.json(0,res)
|
|
|
|
|
|
+ return response.json(0, res)
|
|
else:
|
|
else:
|
|
return response.json(107)
|
|
return response.json(107)
|
|
|
|
|
|
@@ -2626,16 +2648,16 @@ class alexaUidView(TemplateView):
|
|
uid_dict = {}
|
|
uid_dict = {}
|
|
uid_list = []
|
|
uid_list = []
|
|
for uid_q in uid_qs:
|
|
for uid_q in uid_qs:
|
|
- #追加
|
|
|
|
|
|
+ # 追加
|
|
uid_list.append(uid_q['UID'])
|
|
uid_list.append(uid_q['UID'])
|
|
- #给uid_q['UID']赋值
|
|
|
|
|
|
+ # 给uid_q['UID']赋值
|
|
uid_dict[uid_q['UID']] = {'nick': uid_q['NickName'], 'password': uid_q['View_Password']}
|
|
uid_dict[uid_q['UID']] = {'nick': uid_q['NickName'], 'password': uid_q['View_Password']}
|
|
us_qs = UidSetModel.objects.filter(uid__in=uid_list, is_alexa=2).values('uid', 'region_alexa')
|
|
us_qs = UidSetModel.objects.filter(uid__in=uid_list, is_alexa=2).values('uid', 'region_alexa')
|
|
# uid,password,region的列表
|
|
# uid,password,region的列表
|
|
uid_arr = []
|
|
uid_arr = []
|
|
for us in us_qs:
|
|
for us in us_qs:
|
|
uid = us['uid']
|
|
uid = us['uid']
|
|
- #设备alexa区域
|
|
|
|
|
|
+ # 设备alexa区域
|
|
region_alexa = us['region_alexa']
|
|
region_alexa = us['region_alexa']
|
|
if region_alexa == '':
|
|
if region_alexa == '':
|
|
region_alexa = "en"
|
|
region_alexa = "en"
|
|
@@ -2650,6 +2672,7 @@ class alexaUidView(TemplateView):
|
|
else:
|
|
else:
|
|
return response.json(107)
|
|
return response.json(107)
|
|
|
|
|
|
|
|
+
|
|
# 登出
|
|
# 登出
|
|
class V2LogoutView(TemplateView):
|
|
class V2LogoutView(TemplateView):
|
|
@method_decorator(csrf_exempt)
|
|
@method_decorator(csrf_exempt)
|
|
@@ -2811,14 +2834,14 @@ class Image_Code_RegisterView(TemplateView):
|
|
request_dict = request.GET
|
|
request_dict = request.GET
|
|
return self.validates(request_dict)
|
|
return self.validates(request_dict)
|
|
|
|
|
|
- #检测验证码,并注册
|
|
|
|
- def validates(self,request_dict):
|
|
|
|
|
|
+ # 检测验证码,并注册
|
|
|
|
+ def validates(self, request_dict):
|
|
print("__________request_dict:%s" % request_dict)
|
|
print("__________request_dict:%s" % request_dict)
|
|
- userEmail = request_dict.get('userEmail',None)
|
|
|
|
- password = request_dict.get('userPwd',None)
|
|
|
|
- lang = request_dict.get('lang',None)
|
|
|
|
- #前端传进来的uuid
|
|
|
|
- imageCodeId = request_dict.get('imageCodeId',None)
|
|
|
|
|
|
+ userEmail = request_dict.get('userEmail', None)
|
|
|
|
+ password = request_dict.get('userPwd', None)
|
|
|
|
+ lang = request_dict.get('lang', None)
|
|
|
|
+ # 前端传进来的uuid
|
|
|
|
+ imageCodeId = request_dict.get('imageCodeId', None)
|
|
# 页面输入的验证码
|
|
# 页面输入的验证码
|
|
response = ResponseObject(lang)
|
|
response = ResponseObject(lang)
|
|
valid_code = request_dict.get('id_v_code', None)
|
|
valid_code = request_dict.get('id_v_code', None)
|
|
@@ -2839,7 +2862,7 @@ class Image_Code_RegisterView(TemplateView):
|
|
password = base64.b64decode(password)
|
|
password = base64.b64decode(password)
|
|
password = password.decode('utf-8')
|
|
password = password.decode('utf-8')
|
|
password = password[3:-3]
|
|
password = password[3:-3]
|
|
- print("password%s"%password)
|
|
|
|
|
|
+ print("password%s" % password)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(111)
|
|
return response.json(111)
|
|
try:
|
|
try:
|
|
@@ -2856,7 +2879,7 @@ class Image_Code_RegisterView(TemplateView):
|
|
valid_code = base64.b64decode(valid_code)
|
|
valid_code = base64.b64decode(valid_code)
|
|
valid_code = valid_code.decode('utf-8')
|
|
valid_code = valid_code.decode('utf-8')
|
|
valid_code = valid_code[3:-3]
|
|
valid_code = valid_code[3:-3]
|
|
- print("valid_code:%s"%valid_code)
|
|
|
|
|
|
+ print("valid_code:%s" % valid_code)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(121)
|
|
return response.json(121)
|
|
if not userEmail:
|
|
if not userEmail:
|
|
@@ -2870,16 +2893,16 @@ class Image_Code_RegisterView(TemplateView):
|
|
emailValid = Device_User.objects.filter(userEmail=userEmail)
|
|
emailValid = Device_User.objects.filter(userEmail=userEmail)
|
|
if emailValid:
|
|
if emailValid:
|
|
return response.json(103)
|
|
return response.json(103)
|
|
- #根据uuid拼接的key
|
|
|
|
- image_code_key = "image_code_%s" %imageCodeId
|
|
|
|
- #判断验证码是否过期
|
|
|
|
|
|
+ # 根据uuid拼接的key
|
|
|
|
+ image_code_key = "image_code_%s" % imageCodeId
|
|
|
|
+ # 判断验证码是否过期
|
|
if image_code_key is None:
|
|
if image_code_key is None:
|
|
return response.json(120)
|
|
return response.json(120)
|
|
redisObj = RedisObject(db=6)
|
|
redisObj = RedisObject(db=6)
|
|
- #redis里面的验证码
|
|
|
|
|
|
+ # redis里面的验证码
|
|
redis_image_code = redisObj.get_data(key=image_code_key)
|
|
redis_image_code = redisObj.get_data(key=image_code_key)
|
|
- #验证用户输入的验证码和redis中的验证码
|
|
|
|
- if valid_code.lower()!=redis_image_code.lower():
|
|
|
|
|
|
+ # 验证用户输入的验证码和redis中的验证码
|
|
|
|
+ if redis_image_code is False or valid_code.lower() != redis_image_code.lower():
|
|
return response.json(121)
|
|
return response.json(121)
|
|
# 删除redis中的图片验证码,防止用户使用同一个图片验证码验证多次
|
|
# 删除redis中的图片验证码,防止用户使用同一个图片验证码验证多次
|
|
redisObj.del_data(key=image_code_key)
|
|
redisObj.del_data(key=image_code_key)
|
|
@@ -2930,8 +2953,503 @@ class Image_Code_RegisterView(TemplateView):
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
|
|
|
|
|
|
|
|
|
|
+class UserAppFrequencyView(TemplateView):
|
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
|
+ return super(UserAppFrequencyView, self).dispatch(*args, **kwargs)
|
|
|
|
+
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ request_dict = request.POST
|
|
|
|
+ operation = kwargs.get('operation')
|
|
|
|
+ return self.validates(request_dict, operation)
|
|
|
|
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ request_dict = request.GET
|
|
|
|
+ operation = kwargs.get('operation')
|
|
|
|
+ return self.validates(request_dict, operation)
|
|
|
|
|
|
|
|
+ def validates(self, request_dict, operation):
|
|
|
|
+ token = request_dict.get('token', None)
|
|
|
|
+ response = ResponseObject()
|
|
|
|
|
|
|
|
+ token = TokenObject(token)
|
|
|
|
+ if token.code != 0:
|
|
|
|
+ return response.json(token.code)
|
|
|
|
|
|
|
|
+ if operation == 'refresh':
|
|
|
|
+ return self.do_refresh(request_dict, token.userID, response)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(404)
|
|
|
|
+
|
|
|
|
+ def do_refresh(self, request_dict, userID, response):
|
|
|
|
+ type = request_dict.get('type', None)
|
|
|
|
+ month = request_dict.get('month', None)
|
|
|
|
+ if not type or not month:
|
|
|
|
+ return response.json(444, 'type')
|
|
|
|
+ else:
|
|
|
|
+ type = int(type)
|
|
|
|
+ now_time = int(time.time())
|
|
|
|
+ month = int(month)
|
|
|
|
+ uaf_qs = UserAppFrequencyModel.objects.filter(user__userID=userID)
|
|
|
|
+
|
|
|
|
+ if not uaf_qs.exists():
|
|
|
|
+ user = Device_User.objects.filter(userID=userID)[0]
|
|
|
|
+ data = {
|
|
|
|
+ 'user': user,
|
|
|
|
+ 'type': type,
|
|
|
|
+ 'data_time': month,
|
|
|
|
+ 'add_time': now_time,
|
|
|
|
+ 'update_time': now_time,
|
|
|
|
+ }
|
|
|
|
+ UserAppFrequencyModel.objects.create(**data)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ else:
|
|
|
|
+ updateMonth = time.strftime('%m', time.localtime(month))
|
|
|
|
+ uaf = uaf_qs.values('id', 'type', 'data_time')[0]
|
|
|
|
+ dbMonth = time.strftime('%m', time.localtime(int(uaf['data_time'])))
|
|
|
|
+ print('update month is ' + updateMonth)
|
|
|
|
+ print('db month is ' + dbMonth)
|
|
|
|
+ if updateMonth == dbMonth:
|
|
|
|
+ UserAppFrequencyModel.objects.filter(id=uaf['id']).update(type=type)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ elif updateMonth > dbMonth:
|
|
|
|
+ user = Device_User.objects.filter(userID=userID)[0]
|
|
|
|
+ data = {
|
|
|
|
+ 'user': user,
|
|
|
|
+ 'type': type,
|
|
|
|
+ 'data_time': month,
|
|
|
|
+ 'add_time': now_time,
|
|
|
|
+ 'update_time': now_time,
|
|
|
|
+ }
|
|
|
|
+ UserAppFrequencyModel.objects.create(**data)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(444, 'month')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class loginCodeView(View):
|
|
|
|
+ @method_decorator(csrf_exempt) # @csrf_exempt
|
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
|
+ return super(loginCodeView, self).dispatch(*args, **kwargs)
|
|
|
|
+
|
|
|
|
+ @ratelimit(key='ip', rate='2/m')
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ lang = request.POST.get('lang', None)
|
|
|
|
+ if not lang:
|
|
|
|
+ lang = request.POST.get('language', None)
|
|
|
|
+ response = ResponseObject(lang)
|
|
|
|
+ request_dict = request.POST
|
|
|
|
+ phone = request_dict.get('phone', None)
|
|
|
|
+ if phone is not None:
|
|
|
|
+ was_limited = getattr(request, 'limited', False)
|
|
|
|
+ if was_limited is True:
|
|
|
|
+ return response.json(5)
|
|
|
|
+ return self.validate(request_dict, response)
|
|
|
|
+
|
|
|
|
+ @ratelimit(key='ip', rate='2/m')
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ lang = request.GET.get('lang', None)
|
|
|
|
+ if not lang:
|
|
|
|
+ lang = request.GET.get('language', None)
|
|
|
|
+ response = ResponseObject(lang)
|
|
|
|
+ was_limited = getattr(request, 'limited', False)
|
|
|
|
+ if was_limited is True:
|
|
|
|
+ return response.json(5)
|
|
|
|
+ request_dict = request.GET
|
|
|
|
+ return self.validate(request_dict, response)
|
|
|
|
|
|
|
|
+ def validate(self, request_dict, response):
|
|
|
|
+ phone = request_dict.get('phone', None)
|
|
|
|
+ country_code = request_dict.get('country_code', None)
|
|
|
|
+ sign_name = request_dict.get('sign_name', None)
|
|
|
|
+
|
|
|
|
+ if phone and sign_name:
|
|
|
|
+ du_qs = Device_User.objects.filter(Q(phone=phone) | Q(username=phone))
|
|
|
|
+ if not du_qs.exists():
|
|
|
|
+ return response.json(104)
|
|
|
|
+ else:
|
|
|
|
+ redisObject = RedisObject()
|
|
|
|
+ login_code_key = '{phone}_login_code'.format(phone=phone)
|
|
|
|
+ login_code = redisObject.get_data(key=login_code_key)
|
|
|
|
+ login_code_ttl = redisObject.get_ttl(key=login_code_key)
|
|
|
|
+ if login_code_ttl > 240 and login_code:
|
|
|
|
+ return response.json(90)
|
|
|
|
+ login_code = RandomStr(6, True)
|
|
|
|
+ aliSms = AliSmsObject()
|
|
|
|
+ if sign_name == 'zosi':
|
|
|
|
+ sign_sms = '周视'
|
|
|
|
+ else:
|
|
|
|
+ sign_sms = 'Ansjer'
|
|
|
|
+
|
|
|
|
+ res = aliSms.send_code_sms(phone=phone, code=login_code, sign_name=sign_sms, temp_msg='SMS_151675022')
|
|
|
|
+
|
|
|
|
+ if res['Code'] == 'OK':
|
|
|
|
+ if redisObject.set_data(key=login_code_key, val=login_code, expire=300) is not True:
|
|
|
|
+ return response.json(48)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(10, res['Message'])
|
|
|
|
+ else:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class v3LoginByCodeView(View):
|
|
|
|
+ @method_decorator(csrf_exempt) # @csrf_exempt
|
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
|
+ return super(v3LoginByCodeView, self).dispatch(*args, **kwargs)
|
|
|
|
+
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ lang = request.POST.get('lang', None)
|
|
|
|
+ if not lang:
|
|
|
|
+ lang = request.POST.get('language', None)
|
|
|
|
+ response = ResponseObject(lang)
|
|
|
|
+ request_dict = request.POST
|
|
|
|
+ phone = request_dict.get('phone', None)
|
|
|
|
+ if phone is not None:
|
|
|
|
+ was_limited = getattr(request, 'limited', False)
|
|
|
|
+ if was_limited is True:
|
|
|
|
+ return response.json(5)
|
|
|
|
+ return self.validate(request_dict, response)
|
|
|
|
+
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ lang = request.GET.get('lang', None)
|
|
|
|
+ if not lang:
|
|
|
|
+ lang = request.GET.get('language', None)
|
|
|
|
+ response = ResponseObject(lang)
|
|
|
|
+ was_limited = getattr(request, 'limited', False)
|
|
|
|
+ if was_limited is True:
|
|
|
|
+ return response.json(5)
|
|
|
|
+ request_dict = request.GET
|
|
|
|
+ return self.validate(request_dict, response)
|
|
|
|
+
|
|
|
|
+ def validate(self, request_dict, response):
|
|
|
|
+ phone = request_dict.get('phone', None)
|
|
|
|
+ code = request_dict.get('code', None)
|
|
|
|
+
|
|
|
|
+ if phone and code:
|
|
|
|
+ redisObject = RedisObject()
|
|
|
|
+ login_code_key = '{phone}_login_code'.format(phone=phone)
|
|
|
|
+ login_code = redisObject.get_data(key=login_code_key)
|
|
|
|
+
|
|
|
|
+ if login_code is not False:
|
|
|
|
+ print(code)
|
|
|
|
+ code = CommonService.decode_data(code)
|
|
|
|
+ print(code)
|
|
|
|
+ if login_code == code:
|
|
|
|
+ if response.lang is None:
|
|
|
|
+ response.lang = 'en'
|
|
|
|
+ return self.do_phone_login(phone, response)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(121)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(120)
|
|
|
|
+
|
|
|
|
+ def do_phone_login(self, phone, response):
|
|
|
|
+ user_qs = Device_User.objects.filter(Q(phone=phone) | Q(username=phone), is_active=True,
|
|
|
|
+ user_isValid=True)
|
|
|
|
+ return self.valid_login(user_qs, response)
|
|
|
|
+
|
|
|
|
+ def valid_login(self, user_qs, response):
|
|
|
|
+ if not user_qs.exists():
|
|
|
|
+ return response.json(104)
|
|
|
|
+ # users = user_qs.values('role__rid', 'role__roleName', 'userID', 'role', 'NickName', 'username', 'userEmail',
|
|
|
|
+ # 'phone', 'password', 'userIconPath', 'user_isValid', 'is_active')[0]
|
|
|
|
+ users = user_qs.values('role__rid', 'role__roleName', 'userID', 'NickName', 'username', 'userEmail',
|
|
|
|
+ 'phone', 'password', 'userIconPath')[0]
|
|
|
|
+
|
|
|
|
+ userID = users['userID']
|
|
|
|
+ tko = TokenObject()
|
|
|
|
+ res = tko.generate(
|
|
|
|
+ data={'userID': userID, 'lang': response.lang, 'user': users['username'],
|
|
|
|
+ 'm_code': '123413243214'})
|
|
|
|
+ # 添加用户登录类型
|
|
|
|
+ oauth_qs = UserOauth2Model.objects.filter(userID__userID=userID)
|
|
|
|
+ auth_type = 0
|
|
|
|
+ if oauth_qs.exists():
|
|
|
|
+ auth_type = oauth_qs[0].authType
|
|
|
|
+
|
|
|
|
+ if tko.code == 0:
|
|
|
|
+ now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
|
|
|
|
+ user_qs.update(last_login=now_time, language=response.lang)
|
|
|
|
+ res['rid'] = users['role__rid']
|
|
|
|
+ res['roleName'] = users['role__roleName']
|
|
|
|
+ res['permList'] = ModelService.own_permission(userID)
|
|
|
|
+ res['userID'] = userID
|
|
|
|
+ # 昵称,邮箱,电话,刷新,头像
|
|
|
|
+ userIconPath = str(users['userIconPath'])
|
|
|
|
+ if userIconPath and userIconPath.find('static/') != -1:
|
|
|
|
+ userIconPath = userIconPath.replace('static/', '').replace('\\', '/')
|
|
|
|
+ res['userIconUrl'] = SERVER_DOMAIN + 'account/getAvatar/' + userIconPath
|
|
|
|
+ else:
|
|
|
|
+ res['userIconUrl'] = ''
|
|
|
|
+ res['NickName'] = users['NickName'] if users['NickName'] is not None else ''
|
|
|
|
+ res['username'] = users['username'] if users['username'] is not None else ''
|
|
|
|
+ res['userEmail'] = users['userEmail'] if users['userEmail'] is not None else ''
|
|
|
|
+ res['phone'] = users['phone'] if users['phone'] is not None else ''
|
|
|
|
+ res['authType'] = auth_type
|
|
|
|
+ return response.json(0, res)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(tko.code)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class v3LoginByFingerprintView(View):
|
|
|
|
+ @method_decorator(csrf_exempt) # @csrf_exempt
|
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
|
+ return super(v3LoginByFingerprintView, self).dispatch(*args, **kwargs)
|
|
|
|
+
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ lang = request.POST.get('lang', None)
|
|
|
|
+ if not lang:
|
|
|
|
+ lang = request.POST.get('language', None)
|
|
|
|
+ response = ResponseObject(lang)
|
|
|
|
+ request_dict = request.POST
|
|
|
|
+
|
|
|
|
+ was_limited = getattr(request, 'limited', False)
|
|
|
|
+ if was_limited is True:
|
|
|
|
+ return response.json(5)
|
|
|
|
+ return self.validate(request_dict, response)
|
|
|
|
+
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ lang = request.GET.get('lang', None)
|
|
|
|
+ if not lang:
|
|
|
|
+ lang = request.GET.get('language', None)
|
|
|
|
+ response = ResponseObject(lang)
|
|
|
|
+ was_limited = getattr(request, 'limited', False)
|
|
|
|
+ if was_limited is True:
|
|
|
|
+ return response.json(5)
|
|
|
|
+ request_dict = request.GET
|
|
|
|
+ return self.validate(request_dict, response)
|
|
|
|
+
|
|
|
|
+ def validate(self, request_dict, response):
|
|
|
|
+ password = request_dict.get("password", None)
|
|
|
|
+
|
|
|
|
+ if password:
|
|
|
|
+ password = CommonService.decode_data(password)
|
|
|
|
+ if password is None:
|
|
|
|
+ return response.json(444)
|
|
|
|
+ else:
|
|
|
|
+ user_qs = Device_User.objects.filter(username=password, is_active=True, user_isValid=True)
|
|
|
|
+ if not user_qs.exists():
|
|
|
|
+ return response.json(104)
|
|
|
|
+ else:
|
|
|
|
+ users = user_qs.values('role__rid', 'role__roleName', 'userID', 'NickName', 'username', 'userEmail',
|
|
|
|
+ 'phone', 'password', 'userIconPath', 'fingerprint_enable', 'fingerprint_key')[0]
|
|
|
|
+ if users['fingerprint_enable'] == 0:
|
|
|
|
+ return response.json(112)
|
|
|
|
+ else:
|
|
|
|
+ userID = users['userID']
|
|
|
|
+ tko = TokenObject()
|
|
|
|
+ res = tko.generate(
|
|
|
|
+ data={'userID': userID, 'lang': response.lang, 'user': users['username'],
|
|
|
|
+ 'm_code': '123413243214'})
|
|
|
|
+ if tko.code == 0:
|
|
|
|
+ now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
|
|
|
|
+ user_qs.update(last_login=now_time, language=response.lang)
|
|
|
|
+ res['rid'] = users['role__rid']
|
|
|
|
+ res['roleName'] = users['role__roleName']
|
|
|
|
+ res['permList'] = ModelService.own_permission(userID)
|
|
|
|
+ res['userID'] = userID
|
|
|
|
+ # 昵称,邮箱,电话,刷新,头像
|
|
|
|
+ userIconPath = str(users['userIconPath'])
|
|
|
|
+ if userIconPath and userIconPath.find('static/') != -1:
|
|
|
|
+ userIconPath = userIconPath.replace('static/', '').replace('\\', '/')
|
|
|
|
+ res['userIconUrl'] = SERVER_DOMAIN + 'account/getAvatar/' + userIconPath
|
|
|
|
+ else:
|
|
|
|
+ res['userIconUrl'] = ''
|
|
|
|
+ res['NickName'] = users['NickName'] if users['NickName'] is not None else ''
|
|
|
|
+ res['username'] = users['username'] if users['username'] is not None else ''
|
|
|
|
+ res['userEmail'] = users['userEmail'] if users['userEmail'] is not None else ''
|
|
|
|
+ res['phone'] = users['phone'] if users['phone'] is not None else ''
|
|
|
|
+ res['fingerprint_enable'] = users['fingerprint_enable']
|
|
|
|
+ res['fingerprint_key'] = CommonService.encode_data(content=users['fingerprint_key'], start=2)
|
|
|
|
+ return response.json(0, res)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(tko.code)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class v3SetFingerprintView(View):
|
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
|
+ return super(v3SetFingerprintView, self).dispatch(*args, **kwargs)
|
|
|
|
+
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ request_dict = request.POST
|
|
|
|
+ return self.validate(request_dict)
|
|
|
|
+
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ request_dict = request.GET
|
|
|
|
+ return self.validate(request_dict)
|
|
|
|
+
|
|
|
|
+ def validate(self, request_dict):
|
|
|
|
+ lang = request_dict.get('lang', None)
|
|
|
|
+ token = request_dict.get('token', None)
|
|
|
|
+ fingerprint_enable = request_dict.get('fingerprint_enable', None)
|
|
|
|
+ fingerprint_key = request_dict.get('fingerprint_key', None)
|
|
|
|
+
|
|
|
|
+ response = ResponseObject()
|
|
|
|
+
|
|
|
|
+ token = TokenObject(token)
|
|
|
|
+ if token.code != 0:
|
|
|
|
+ return response.json(token.code)
|
|
|
|
+
|
|
|
|
+ if not lang:
|
|
|
|
+ return response.json(444, 'lang')
|
|
|
|
+
|
|
|
|
+ response.lang = lang
|
|
|
|
+
|
|
|
|
+ data = {}
|
|
|
|
+
|
|
|
|
+ if fingerprint_enable:
|
|
|
|
+ data['fingerprint_enable'] = int(fingerprint_enable)
|
|
|
|
+
|
|
|
|
+ if fingerprint_key:
|
|
|
|
+ data['fingerprint_key'] = CommonService.decode_data(fingerprint_key, end=3)
|
|
|
|
+
|
|
|
|
+ if len(data) > 0:
|
|
|
|
+ Device_User.objects.filter(userID=token.userID).update(**data)
|
|
|
|
+ return response.json(0)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class AppleAuthLogin(View):
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ request_dict = request.POST
|
|
|
|
+ return self.validate(request_dict)
|
|
|
|
+
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ request_dict = request.GET
|
|
|
|
+ return self.validate(request_dict)
|
|
|
|
+
|
|
|
|
+ def validate(self, request_dict):
|
|
|
|
+ lang = request_dict.get('lang', None)
|
|
|
|
+ identity_token = request_dict.get('identity_token', None)
|
|
|
|
+ app_bundle_id = request_dict.get('app_bundle_id', None) # 包名
|
|
|
|
+
|
|
|
|
+ response = ResponseObject(lang)
|
|
|
|
+ identity_token = CommonService.decode_data(identity_token)
|
|
|
|
+ # print(identity_token)
|
|
|
|
+ if identity_token:
|
|
|
|
+ key_url = 'https://appleid.apple.com/auth/keys'
|
|
|
|
+ key_response = requests.get(key_url).json()
|
|
|
|
+ # print(key_response)
|
|
|
|
+ head = jwt.get_unverified_header(identity_token)
|
|
|
|
+ # print(head)
|
|
|
|
+ token_key = head['kid']
|
|
|
|
+ key_object = None
|
|
|
|
+ alg = None
|
|
|
|
+ for pub_key in key_response['keys']:
|
|
|
|
+ if pub_key['kid'] == token_key:
|
|
|
|
+ key_object = simplejson.dumps(pub_key)
|
|
|
|
+ key_object = RSAAlgorithm.from_jwk(key_object)
|
|
|
|
+ alg = pub_key['alg']
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ if key_object:
|
|
|
|
+ try:
|
|
|
|
+ claims = jwt.decode(identity_token, key=key_object, verify=True, algorithms=[alg], audience=app_bundle_id)
|
|
|
|
+ unionID = claims['sub']
|
|
|
|
+ print(claims)
|
|
|
|
+ user_extend_qs = UserOauth2Model.objects.filter(unionID=unionID, authType=2)
|
|
|
|
+ if user_extend_qs.exists():
|
|
|
|
+ # 如果用户绑定过则直接登录
|
|
|
|
+ userID = user_extend_qs[0].userID_id
|
|
|
|
+ print(userID)
|
|
|
|
+ user_qs = Device_User.objects.filter(userID=userID)
|
|
|
|
+ return self.do_login(user_qs, response)
|
|
|
|
+ else:
|
|
|
|
+ # 如果用户为绑定过则创建用户并进行登录返回token
|
|
|
|
+ userID = CommonService.getUserID(getUser=False)
|
|
|
|
+ if claims.__contains__('email'):
|
|
|
|
+ nickname = claims['email']
|
|
|
|
+ else:
|
|
|
|
+ nickname = 'apple_{num}'.format(num=CommonService.RandomStr(6, False))
|
|
|
|
+ return self.do_register(userID, nickname, response, app_bundle_id, unionID)
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(717)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(444)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+ # 登录
|
|
|
|
+ def do_login(self, user_qs, response):
|
|
|
|
+ now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
|
|
|
|
+ userID = user_qs[0].userID
|
|
|
|
+ print('userID' + userID)
|
|
|
|
+ tko = TokenObject()
|
|
|
|
+ user_list = user_qs.values("NickName", "userIconUrl", "userIconPath", "username", "userEmail", "phone")
|
|
|
|
+ res = tko.generate(data={'userID': userID, 'lang': response.lang, 'user': user_list[0]["username"]})
|
|
|
|
+ # 增加角色
|
|
|
|
+ user_qs[0].role.add(Role.objects.get(rid=1))
|
|
|
|
+ role_dict = ModelService.own_role(userID=userID)
|
|
|
|
+ res['rid'] = role_dict['rid']
|
|
|
|
+ res['roleName'] = role_dict['roleName']
|
|
|
|
+ res['permList'] = ModelService.own_permission(userID)
|
|
|
|
+ res['userID'] = userID
|
|
|
|
+ # 昵称,邮箱,电话,刷新,头像
|
|
|
|
+ userIconPath = str(user_list[0]["userIconPath"])
|
|
|
|
+ if userIconPath and userIconPath.find('static/') != -1:
|
|
|
|
+ userIconPath = userIconPath.replace('static/', '').replace('\\', '/')
|
|
|
|
+ res['userIconUrl'] = SERVER_DOMAIN + 'account/getAvatar/' + userIconPath
|
|
|
|
+ else:
|
|
|
|
+ res['userIconUrl'] = ''
|
|
|
|
+ res['NickName'] = user_list[0]["NickName"] if user_list[0]["NickName"] is not None else ''
|
|
|
|
+ res['username'] = user_list[0]["username"] if user_list[0]["username"] is not None else ''
|
|
|
|
+ res['userEmail'] = user_list[0]["userEmail"] if user_list[0]["userEmail"] is not None else ''
|
|
|
|
+ res['phone'] = user_list[0]["phone"] if user_list[0]["phone"] is not None else ''
|
|
|
|
+ print(res)
|
|
|
|
+ # 添加用户登录类型
|
|
|
|
+ oauth_qs = UserOauth2Model.objects.filter(userID__userID=userID)
|
|
|
|
+ auth_type = 0
|
|
|
|
+ if oauth_qs.exists():
|
|
|
|
+ auth_type = oauth_qs[0].authType
|
|
|
|
+ res['authType'] = auth_type
|
|
|
|
+ user_qs.update(last_login=now_time, online=True)
|
|
|
|
+ return response.json(0, res)
|
|
|
|
+
|
|
|
|
+ def do_register(self, userID, nickname, response, appBundleId, unionID):
|
|
|
|
+ data_valid = DataValid()
|
|
|
|
+ if data_valid.name_validate(userID) is not True:
|
|
|
|
+ return response.json(105)
|
|
|
|
+ try:
|
|
|
|
+ users = Device_User.objects.create(
|
|
|
|
+ username=userID,
|
|
|
|
+ NickName=nickname,
|
|
|
|
+ password=make_password('123456'),
|
|
|
|
+ userID=userID,
|
|
|
|
+ is_active=True,
|
|
|
|
+ user_isValid=True,
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ nowTime = int(time.time())
|
|
|
|
+ UserOauth2Model.objects.create(
|
|
|
|
+ addTime=nowTime,
|
|
|
|
+ updTime=nowTime,
|
|
|
|
+ userID_id=users.userID,
|
|
|
|
+ authType=2,
|
|
|
|
+ unionID=unionID
|
|
|
|
+ )
|
|
|
|
+ except Exception as e:
|
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
|
+ print(errorInfo)
|
|
|
|
+ return response.json(424, repr(e))
|
|
|
|
+ else:
|
|
|
|
+ user_qs = Device_User.objects.filter(Q(userID=userID))
|
|
|
|
+ print('---')
|
|
|
|
+ print(user_qs)
|
|
|
|
+ return self.do_login(user_qs, response)
|