|
@@ -1294,7 +1294,7 @@ class InitInfoView(View):
|
|
|
if appBundleId not in JPUSH_CONFIG.keys():
|
|
|
return response.json(904)
|
|
|
else:
|
|
|
- return response.json(444,'push_type')
|
|
|
+ return response.json(444, 'push_type')
|
|
|
uid_list = ModelService.get_uid_list(userID=userID)
|
|
|
if uid_list:
|
|
|
# 获取设备推送状态
|
|
@@ -1304,7 +1304,8 @@ class InitInfoView(View):
|
|
|
'tz': tz,
|
|
|
}
|
|
|
# 更新当前用户推送设备状态
|
|
|
- UidPushModel.objects.filter(userID_id=userID, m_code=m_code,uid_set__detect_status=1).update(**update_dict)
|
|
|
+ UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__detect_status=1).update(
|
|
|
+ **update_dict)
|
|
|
if appBundleId:
|
|
|
user_extend_qs = UserExtendModel.objects.filter(userID_id=userID)
|
|
|
if user_extend_qs.exists():
|
|
@@ -1527,321 +1528,81 @@ class wxAuthSignView(TemplateView):
|
|
|
print(user_qs)
|
|
|
return self.do_login(user_qs, response)
|
|
|
|
|
|
-# 获取验证码
|
|
|
-class OauthAuthCodeView(TemplateView):
|
|
|
+<<<<<<< HEAD
|
|
|
|
|
|
- @method_decorator(csrf_exempt)
|
|
|
- def dispatch(self, *args, **kwargs):
|
|
|
- return super(OauthAuthCodeView, self).dispatch(*args, **kwargs)
|
|
|
+# 获取验证码
|
|
|
+class wxPerfectView(TemplateView):
|
|
|
|
|
|
- @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.ValidationError(request_dict, response)
|
|
|
|
|
|
- @ratelimit(key='ip', rate='2/m')
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
# Device_User.objects.filter(userEmail='chanjunkai@163.com').delete()
|
|
|
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.do_register('157113010663213800138000', '157113010663213800138000', response, 'xx')
|
|
|
return self.ValidationError(request_dict, response)
|
|
|
|
|
|
def ValidationError(self, request_dict, response):
|
|
|
- email = request_dict.get('email', None)
|
|
|
- phone = request_dict.get('phone', None)
|
|
|
- country_code = request_dict.get('country_code', None)
|
|
|
- sign_name = request_dict.get('sign_name', None)
|
|
|
- token = request_dict.get('token', None)
|
|
|
- print (token)
|
|
|
- if email is not None:
|
|
|
- email = email.strip()
|
|
|
- # 阿里云的发送邮箱的调用方法
|
|
|
- return self.aliyun_emailCode(email, response)
|
|
|
-
|
|
|
- # return self.emailCode(email, response)
|
|
|
- elif phone is not None:
|
|
|
- phone = phone.strip()
|
|
|
- if country_code is None:
|
|
|
- return self.phoneCode(phone, response, sign_name)
|
|
|
- else:
|
|
|
- country_code = str(country_code.strip())
|
|
|
- return self.phoneCodeV2(country_code, phone, response, sign_name)
|
|
|
- else:
|
|
|
- return response.json(444)
|
|
|
-
|
|
|
- def emailCode(self, email, response):
|
|
|
-
|
|
|
- dataValid = DataValid()
|
|
|
- # 邮箱匹配
|
|
|
- if dataValid.email_validate(email) is False:
|
|
|
- return response.json(107)
|
|
|
- reds = RedisObject()
|
|
|
- identifyingCode = reds.get_data(key=email + '_OauthPerfect')
|
|
|
- # 是否以获取邮箱验证码
|
|
|
- if identifyingCode:
|
|
|
- return response.json(89)
|
|
|
- user_qs = Device_User.objects.filter(username=email)
|
|
|
- email_qs = Device_User.objects.filter(userEmail=email)
|
|
|
- # 邮箱用户是否已存在
|
|
|
- if user_qs.exists():
|
|
|
- return response.json(103)
|
|
|
- elif email_qs.exists():
|
|
|
- return response.json(103)
|
|
|
- # 生成随机6位数
|
|
|
- identifyingCode = RandomStr(6, True)
|
|
|
- # 设置随机数缓存生命周期
|
|
|
- send_data = TemplateService.email_message(type='register_code', language=response.lang)
|
|
|
- ses = SesClassObject()
|
|
|
- # 发送邮件
|
|
|
- send_res = ses.send_email(
|
|
|
- send_address_list=[email],
|
|
|
- subject=send_data['title'],
|
|
|
- body=send_data['body'].replace("{username}", email).replace("{captcha}",
|
|
|
- str(identifyingCode))
|
|
|
- )
|
|
|
- if send_res is not True:
|
|
|
- return response.json(44)
|
|
|
- if reds.set_data(key=email + '_OauthPerfect', val=identifyingCode, expire=600) is not True:
|
|
|
- return response.json(10, 'error')
|
|
|
- return response.json(0)
|
|
|
- # return response.json(0, {'identifyingCode': identifyingCode})
|
|
|
-
|
|
|
- # 阿里云获取邮箱验证码
|
|
|
- def aliyun_emailCode(self, email, response):
|
|
|
- print('阿里云开始')
|
|
|
- dataValid = DataValid()
|
|
|
- # 邮箱匹配
|
|
|
- if dataValid.email_validate(email) is False:
|
|
|
- return response.json(107)
|
|
|
- reds = RedisObject()
|
|
|
- identifyingCode = reds.get_data(key=email + '_OauthPerfect')
|
|
|
- # 是否以获取邮箱验证码
|
|
|
- if identifyingCode:
|
|
|
- return response.json(89)
|
|
|
- user_qs = Device_User.objects.filter(username=email)
|
|
|
- email_qs = Device_User.objects.filter(userEmail=email)
|
|
|
- # 邮箱用户是否已存在
|
|
|
- if user_qs.exists():
|
|
|
- return response.json(103)
|
|
|
- elif email_qs.exists():
|
|
|
- return response.json(103)
|
|
|
- # 生成随机6位数
|
|
|
- identifyingCode = RandomStr(6, True)
|
|
|
- # 设置随机数缓存生命周期
|
|
|
- send_data = TemplateService.email_message(type='register_code', language=response.lang)
|
|
|
- ses = SesClassObject()
|
|
|
- # 发送邮件
|
|
|
- send_res = ses.alyEmailCode(
|
|
|
- send_address_list=[email],
|
|
|
- subject=send_data['title'],
|
|
|
- body=send_data['body'].replace("{username}", email).replace("{captcha}", str(identifyingCode))
|
|
|
- )
|
|
|
- if send_res is not True:
|
|
|
- return response.json(44)
|
|
|
- if reds.set_data(key=email + '_OauthPerfect', val=identifyingCode, expire=600) is not True:
|
|
|
- return response.json(10, 'error')
|
|
|
- return response.json(0)
|
|
|
-
|
|
|
- def phoneCode(self, phone, response, sign_name):
|
|
|
- dataValid = DataValid()
|
|
|
- if dataValid.mobile_validate(phone) is not True:
|
|
|
- return response.json(107)
|
|
|
- reds = RedisObject()
|
|
|
- reds_key = str(phone) + '_OauthPerfect'
|
|
|
- identifyingCode = reds.get_data(key=reds_key)
|
|
|
- reds_key_ttl = reds.get_ttl(key=reds_key)
|
|
|
- if reds_key_ttl > 240 and identifyingCode:
|
|
|
- # if identifyingCode :
|
|
|
- return response.json(90)
|
|
|
- user_qs = Device_User.objects.filter(username=phone)
|
|
|
- phone_qs = Device_User.objects.filter(phone=phone)
|
|
|
- if user_qs.exists() or phone_qs.exists():
|
|
|
- return response.json(101)
|
|
|
- identifyingCode = RandomStr(6, True)
|
|
|
- # 发送手机验证码
|
|
|
- aliSms = AliSmsObject()
|
|
|
- if sign_name == 'zosi':
|
|
|
- sign_ms = '周视'
|
|
|
- else:
|
|
|
- sign_ms = 'Ansjer'
|
|
|
- res = aliSms.send_code_sms(phone=phone, code=identifyingCode, sign_name=sign_ms,
|
|
|
- temp_msg='SMS_151600991')
|
|
|
- print(res)
|
|
|
- if res["Code"] == "OK":
|
|
|
- if reds.set_data(key=reds_key, val=identifyingCode, expire=300) is not True:
|
|
|
- # if reds.set_data(key=phone + '_identifyingCode', val=identifyingCode, expire=60) is not True:
|
|
|
-
|
|
|
- return response.json(10, '生成缓存系统错误')
|
|
|
- return response.json(0)
|
|
|
- else:
|
|
|
- return response.json(10, res["Message"])
|
|
|
-
|
|
|
- def phoneCodeV2(self, country_code, phone, response, sign_name):
|
|
|
- dataValid = DataValid()
|
|
|
- if dataValid.mobile_validate(phone) is not True:
|
|
|
- return response.json(107)
|
|
|
- reds = RedisObject()
|
|
|
- reds_key = str(phone) + '_OauthPerfect'
|
|
|
- identifyingCode = reds.get_data(key=reds_key)
|
|
|
- reds_key_ttl = reds.get_ttl(key=reds_key)
|
|
|
- if reds_key_ttl > 240 and identifyingCode:
|
|
|
- # if identifyingCode :
|
|
|
- return response.json(90)
|
|
|
- user_qs = Device_User.objects.filter(username=phone)
|
|
|
- phone_qs = Device_User.objects.filter(phone=phone)
|
|
|
- if user_qs.exists() or phone_qs.exists():
|
|
|
- return response.json(101)
|
|
|
- identifyingCode = RandomStr(6, True)
|
|
|
- # 短信签名
|
|
|
- # sign_name_dict = {
|
|
|
- # 'ansjer':'Ansjer',
|
|
|
- # 'zosi':'周视'
|
|
|
- # }
|
|
|
- sign_ms = ''
|
|
|
- if country_code == '86':
|
|
|
- # 国内短信推送模板
|
|
|
- temp_msg = 'SMS_151600991'
|
|
|
- rec_phone = phone
|
|
|
- if sign_name == 'zosi':
|
|
|
- sign_ms = '周视'
|
|
|
+ grant_code = request_dict.get('grant_code', None) # 微信授权code
|
|
|
+ appBundleID = request_dict.get('appBundleID', None) # 包名
|
|
|
+ token = request_dict.get('token', None) # 包名
|
|
|
+ if all([grant_code, appBundleID, token]):
|
|
|
+ tko = TokenObject(token)
|
|
|
+ if tko.code == 0:
|
|
|
+ userID = tko.userID
|
|
|
+ app_config = {
|
|
|
+ 'com.ansjer.zccloud': {'appid': 'wx2a9f5ef9baf2760f', 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
|
+ # ios
|
|
|
+ 'com.ansjer.zccloud_ab': {'appid': 'wx2a9f5ef9baf2760f',
|
|
|
+ 'secret': '5d38c7079676463149ffea593c58f2ed'},
|
|
|
+ # android
|
|
|
+ }
|
|
|
+ if appBundleID in app_config.keys():
|
|
|
+ appid = app_config[appBundleID]['appid']
|
|
|
+ secret = app_config[appBundleID]['secret']
|
|
|
+ # 获取access_token请求
|
|
|
+ at_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid={appid}&secret={secret}&code={code}&grant_type=authorization_code'.format(
|
|
|
+ appid=appid, secret=secret, code=grant_code)
|
|
|
+ res_req = requests.get(url=at_url)
|
|
|
+ res_json = res_req.json()
|
|
|
+ print(res_json)
|
|
|
+ if 'access_token' not in res_json.keys():
|
|
|
+ # 授权过期
|
|
|
+ return response.json(717)
|
|
|
+ access_token = res_json['access_token']
|
|
|
+ openid = res_json['openid']
|
|
|
+ if access_token and openid:
|
|
|
+ user_extend_qs = UserExtendModel.objects. \
|
|
|
+ filter(userID_id=userID, authType=1, appBundleId=appBundleID)
|
|
|
+ if user_extend_qs.exists():
|
|
|
+ user_extend_qs.update(authOpenID=openid)
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ try:
|
|
|
+ nowTime = int(time.time())
|
|
|
+ UserExtendModel.objects.create(
|
|
|
+ addTime=nowTime,
|
|
|
+ updTime=nowTime,
|
|
|
+ appBundleId=appBundleID,
|
|
|
+ userID_id=userID,
|
|
|
+ authType=1,
|
|
|
+ authOpenID=openid)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(424, repr(e))
|
|
|
+ else:
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(414, 'access_token,openid')
|
|
|
+ else:
|
|
|
+ return response.json(414, 'appBundleID is wrong!')
|
|
|
else:
|
|
|
- sign_ms = 'Ansjer'
|
|
|
- else:
|
|
|
- # 国际短信推送模板
|
|
|
- temp_msg = 'SMS_172165867'
|
|
|
- rec_phone = country_code + phone
|
|
|
- sign_ms = 'Ansjer'
|
|
|
-
|
|
|
- # 发送手机验证码
|
|
|
- aliSms = AliSmsObject()
|
|
|
- res = aliSms.send_code_sms(phone=rec_phone, code=identifyingCode, sign_name=sign_ms,
|
|
|
- temp_msg=temp_msg)
|
|
|
- print(res)
|
|
|
- if res["Code"] == "OK":
|
|
|
- # if reds.set_data(key=reds_key, val=identifyingCode, expire=60) is not True:
|
|
|
- if reds.set_data(key=reds_key, val=identifyingCode, expire=300) is not True:
|
|
|
- return response.json(10, '生成缓存系统错误')
|
|
|
- return response.json(0)
|
|
|
- else:
|
|
|
- return response.json(10, res["Message"])
|
|
|
-
|
|
|
-class OauthPerfectView(TemplateView):
|
|
|
- @method_decorator(csrf_exempt)
|
|
|
- def dispatch(self, *args, **kwargs):
|
|
|
- return super(OauthPerfectView, self).dispatch(*args, **kwargs)
|
|
|
-
|
|
|
- def get(self, request, *args, **kwargs):
|
|
|
- request.encoding = 'utf-8'
|
|
|
- request_dict = request.GET
|
|
|
- lang = request_dict.get('lang')
|
|
|
- if not lang:
|
|
|
- lang = request_dict.get('language', None)
|
|
|
- response = ResponseObject(lang)
|
|
|
- was_limited = getattr(request, 'limited', False)
|
|
|
- if was_limited is True:
|
|
|
- return response.json(5)
|
|
|
- return self.ValidationError(request_dict, response)
|
|
|
-
|
|
|
- def post(self, request):
|
|
|
- request.encoding = 'utf-8'
|
|
|
- request_dict = request.POST
|
|
|
- lang = request_dict.get('lang')
|
|
|
- if not lang:
|
|
|
- lang = request_dict.get('language', None)
|
|
|
- response = ResponseObject(lang)
|
|
|
- was_limited = getattr(request, 'limited', False)
|
|
|
- if was_limited is True:
|
|
|
- return response.json(5)
|
|
|
- return self.ValidationError(request_dict, response)
|
|
|
-
|
|
|
- def ValidationError(self, request_dict, response):
|
|
|
- phone = request_dict.get('phone', None)
|
|
|
- email = request_dict.get('email', None)
|
|
|
- password = request_dict.get('password', None)
|
|
|
- authcode = request_dict.get('authcode', None)
|
|
|
- token = request_dict.get('token', None)
|
|
|
- print (token)
|
|
|
- token = request_dict.get('token')
|
|
|
- tko = TokenObject(token)
|
|
|
- if password is None or authcode is None:
|
|
|
- return response.json(444, 'password,authcode')
|
|
|
- authcode = authcode.strip()
|
|
|
- password = password.strip()
|
|
|
- if phone is not None:
|
|
|
- phone = phone.strip()
|
|
|
- return self.do_phone(tko,phone, authcode, password, response)
|
|
|
- elif email is not None:
|
|
|
- email = email.strip()
|
|
|
- return self.do_email(tko,email, authcode, password, response)
|
|
|
- else:
|
|
|
- return response.json(444, 'phone')
|
|
|
-
|
|
|
- def do_email(self,tko, email, authcode, password, response):
|
|
|
- data_valid = DataValid()
|
|
|
- if data_valid.email_validate(email) is not True:
|
|
|
- return response.json(105)
|
|
|
- if data_valid.password_validate(password) is not True:
|
|
|
- return response.json(109)
|
|
|
-
|
|
|
- if tko.code == 0:
|
|
|
- user_qs = Device_User.objects.filter(userID=tko.userID)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
- if not user_qs.exists():
|
|
|
- return response.json(104)
|
|
|
- reds = RedisObject()
|
|
|
- resetCode = reds.get_data(key=email + '_OauthPerfect')
|
|
|
- if resetCode is False:
|
|
|
- return response.json(90)
|
|
|
- if authcode != resetCode:
|
|
|
- return response.json(121)
|
|
|
- # if not reds.set_data(key=email + '_forgetPwdResetCode', val=resetCode, expire=300):
|
|
|
- # return response.json(10, '生成缓存错误')
|
|
|
- user_qs.update(userEmail=email,password=make_password(password))
|
|
|
- if not reds.del_data(email + '_OauthPerfect'):
|
|
|
- return response.json(10, '删除缓存失败')
|
|
|
- return response.json(0)
|
|
|
-
|
|
|
- def do_phone(self,tko, phone, authcode, password, response):
|
|
|
- data_valid = DataValid()
|
|
|
- if data_valid.mobile_validate(phone) is not True:
|
|
|
- return response.json(100)
|
|
|
- if data_valid.password_validate(password) is not True:
|
|
|
- return response.json(109)
|
|
|
-
|
|
|
- if tko.code == 0:
|
|
|
- user_qs = Device_User.objects.filter(userID=tko.userID)
|
|
|
+ return response.json(tko.code)
|
|
|
else:
|
|
|
- return response.json(tko.code)
|
|
|
- if not user_qs.exists():
|
|
|
- return response.json(102)
|
|
|
- reds = RedisObject()
|
|
|
- resetCode = reds.get_data(key=str(phone) + '_OauthPerfect')
|
|
|
- print (resetCode)
|
|
|
- if resetCode is False:
|
|
|
- return response.json(90)
|
|
|
- if authcode != resetCode:
|
|
|
- return response.json(121)
|
|
|
- # if not reds.set_data(key=phone + '_forgetPwdResetCode', val=resetCode, expire=300):
|
|
|
- # return response.json(10, '生成缓存错误')
|
|
|
- user_qs.update(phone=phone,password=make_password(password))
|
|
|
- if not reds.del_data(str(phone) + '_OauthPerfect'):
|
|
|
- return response.json(10, '删除缓存失败')
|
|
|
- return response.json(0)
|
|
|
+ return response.json(414)
|