|
@@ -336,6 +336,50 @@ class ChangePwdView(TemplateView):
|
|
|
request_dict = request.GET
|
|
|
return self.validates(request_dict)
|
|
|
|
|
|
+ def validates(self, request_dict):
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ oldPwd = request_dict.get('oldPwd', None)
|
|
|
+ newPwd = request_dict.get('newPwd', None)
|
|
|
+ response = ResponseObject()
|
|
|
+ if oldPwd is None and newPwd is None:
|
|
|
+ return response.json(800)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ return self.updatePwd(tko.userID, oldPwd, newPwd, response)
|
|
|
+
|
|
|
+ def updatePwd(self, userID, oldPwd, newPwd, response):
|
|
|
+ user_qs = Device_User.objects.filter(userID=userID)
|
|
|
+ if not user_qs.exists():
|
|
|
+ return response.json(104)
|
|
|
+ c_p = check_password(oldPwd, user_qs[0].password)
|
|
|
+ # 密码是否正确
|
|
|
+ if not c_p:
|
|
|
+ return response.json(111)
|
|
|
+ update = user_qs.update(password=make_password(newPwd))
|
|
|
+ if update:
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(177)
|
|
|
+
|
|
|
+
|
|
|
+# 修改密码v3
|
|
|
+class v3ChangePwdView(TemplateView):
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
+ return super(v3ChangePwdView, self).dispatch(*args, **kwargs)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ request_dict = request.POST
|
|
|
+ return self.validates(request_dict)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ request_dict = request.GET
|
|
|
+ return self.validates(request_dict)
|
|
|
+
|
|
|
def validates(self, request_dict):
|
|
|
token = request_dict.get('token', None)
|
|
|
oldPwd = request_dict.get('oldPwd', None)
|
|
@@ -395,6 +439,7 @@ class ChangePwdView(TemplateView):
|
|
|
return response.json(177)
|
|
|
|
|
|
|
|
|
+
|
|
|
class ForgetPwdView(TemplateView):
|
|
|
'''
|
|
|
忘记密码
|
|
@@ -802,6 +847,147 @@ class v2registerView(TemplateView):
|
|
|
request_dict = request.GET
|
|
|
return self.validates(request_dict)
|
|
|
|
|
|
+ def validates(self, request_dict):
|
|
|
+ phone = request_dict.get('phone', None)
|
|
|
+ email = request_dict.get('email', None)
|
|
|
+ password = request_dict.get('password', None)
|
|
|
+ authcode = request_dict.get('authcode', None)
|
|
|
+ lang = request_dict.get('lang', None)
|
|
|
+ response = ResponseObject(lang)
|
|
|
+ if not lang:
|
|
|
+ lang = request_dict.get('language', None)
|
|
|
+ if password is None:
|
|
|
+ return response.json(444, 'password')
|
|
|
+ if authcode is None:
|
|
|
+ return response.json(444, 'identifyingCode')
|
|
|
+ if phone is not None:
|
|
|
+ return self.do_phone_register(phone, password, authcode, response)
|
|
|
+ elif email is not None:
|
|
|
+ return self.do_email_register(email, password, authcode, response)
|
|
|
+ else:
|
|
|
+ return response.json(444, 'phone or email')
|
|
|
+
|
|
|
+ def do_phone_register(self, phone, password, authcode, 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)
|
|
|
+ reds = RedisObject()
|
|
|
+ identifyingCode = reds.get_data(key=phone + '_identifyingCode')
|
|
|
+ # 判断验证码是否过期
|
|
|
+ if identifyingCode is False:
|
|
|
+ return response.json(120)
|
|
|
+ # 验证码是否正确
|
|
|
+ if authcode != identifyingCode:
|
|
|
+ return response.json(121)
|
|
|
+ phone_qs = Device_User.objects.filter(Q(phone=phone) | Q(username=phone))
|
|
|
+ # 是否已存在
|
|
|
+ if phone_qs.exists():
|
|
|
+ return response.json(101)
|
|
|
+ try:
|
|
|
+ users = Device_User.objects.create(
|
|
|
+ username=phone,
|
|
|
+ NickName=phone,
|
|
|
+ phone=phone,
|
|
|
+ password=make_password(password),
|
|
|
+ userID=CommonService.getUserID(μs=False, setOTAID=True),
|
|
|
+ is_active=True,
|
|
|
+ user_isValid=True,
|
|
|
+ )
|
|
|
+ except Exception as e:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(424, repr(e))
|
|
|
+ else:
|
|
|
+ if not reds.del_data(key=phone + '_identifyingCode'):
|
|
|
+ return response.json(10, '删除缓存验证码错误')
|
|
|
+ return self.do_login(phone_qs, response)
|
|
|
+
|
|
|
+ def do_login(self, user_qs, response):
|
|
|
+ now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
|
|
|
+ user_qs.update(last_login=now_time, online=True)
|
|
|
+ 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)
|
|
|
+ return response.json(0, res)
|
|
|
+
|
|
|
+ def do_email_register(self, email, password, authcode, 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)
|
|
|
+ reds = RedisObject()
|
|
|
+ identifyingCode = reds.get_data(key=email + '_identifyingCode')
|
|
|
+ # 判断验证码是否过期
|
|
|
+ if identifyingCode is False:
|
|
|
+ return response.json(120)
|
|
|
+ # 验证码是否正确
|
|
|
+ if authcode != identifyingCode:
|
|
|
+ return response.json(121)
|
|
|
+ email_qs = Device_User.objects.filter(Q(userEmail=email) | Q(username=email))
|
|
|
+ # 是否已存在
|
|
|
+ if email_qs.exists():
|
|
|
+ return response.json(103)
|
|
|
+ try:
|
|
|
+ users = Device_User.objects.create(
|
|
|
+ username=email,
|
|
|
+ NickName=email,
|
|
|
+ userEmail=email,
|
|
|
+ password=make_password(password),
|
|
|
+ userID=CommonService.getUserID(μs=False, setOTAID=True),
|
|
|
+ is_active=True,
|
|
|
+ user_isValid=True,
|
|
|
+ )
|
|
|
+ except Exception as e:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(424, repr(e))
|
|
|
+ else:
|
|
|
+ if not reds.del_data(key=email + '_identifyingCode'):
|
|
|
+ return response.json(10, '删除缓存验证码错误')
|
|
|
+ return self.do_login(email_qs, response)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# 验证码注册v3
|
|
|
+class v3registerView(TemplateView):
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
+ return super(v3registerView, self).dispatch(*args, **kwargs)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ request_dict = request.POST
|
|
|
+ return self.validates(request_dict)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ request_dict = request.GET
|
|
|
+ return self.validates(request_dict)
|
|
|
+
|
|
|
def validates(self, request_dict):
|
|
|
phone = request_dict.get('phone', None)
|
|
|
email = request_dict.get('email', None)
|
|
@@ -824,6 +1010,7 @@ class v2registerView(TemplateView):
|
|
|
password = base64.b64decode(password)
|
|
|
password = password.decode('utf-8')
|
|
|
password = password[3:-3]
|
|
|
+ print(password)
|
|
|
except Exception as e:
|
|
|
return response.json(111)
|
|
|
else:
|
|
@@ -903,7 +1090,6 @@ class v2registerView(TemplateView):
|
|
|
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)
|
|
|
return response.json(0, res)
|
|
|
|
|
|
def do_email_register(self, email, password, authcode, response):
|
|
@@ -944,6 +1130,7 @@ class v2registerView(TemplateView):
|
|
|
return self.do_login(email_qs, response)
|
|
|
|
|
|
|
|
|
+
|
|
|
# 重置密码
|
|
|
# 忘记密码获取验证码v2
|
|
|
class v2forgetPwdCodeView(TemplateView):
|
|
@@ -1116,6 +1303,130 @@ class v2resetPwdByCodeView(TemplateView):
|
|
|
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)
|
|
|
+ print("1111111111111111111111")
|
|
|
+ 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_pwd_reset(phone, authcode, password, response)
|
|
|
+ elif email is not None:
|
|
|
+ email = email.strip()
|
|
|
+ return self.do_email_pwd_reset(email, authcode, password, response)
|
|
|
+ else:
|
|
|
+ return response.json(444, 'phone')
|
|
|
+
|
|
|
+ def do_email_pwd_reset(self, 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)
|
|
|
+ user_qs = Device_User.objects.filter(Q(userEmail=email) | Q(username=email))
|
|
|
+ if not user_qs.exists():
|
|
|
+ return response.json(104)
|
|
|
+ reds = RedisObject()
|
|
|
+ resetCode = reds.get_data(key=email + '_forgetPwdResetCode')
|
|
|
+ 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(password=make_password(password))
|
|
|
+ if not reds.del_data(email + '_forgetPwdResetCode'):
|
|
|
+ return response.json(10, '删除缓存失败')
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ def do_phone_pwd_reset(self, 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)
|
|
|
+ user_qs = Device_User.objects.filter(Q(phone=phone) | Q(username=phone))
|
|
|
+ if not user_qs.exists():
|
|
|
+ return response.json(102)
|
|
|
+ reds = RedisObject()
|
|
|
+ resetCode = reds.get_data(key=phone + '_forgetPwdResetCode')
|
|
|
+ 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(password=make_password(password))
|
|
|
+ if not reds.del_data(phone + '_forgetPwdResetCode'):
|
|
|
+ return response.json(10, '删除缓存失败')
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ def do_login(self, user_qs, response):
|
|
|
+ now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
|
|
|
+ user_qs.update(last_login=now_time, online=True)
|
|
|
+ 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)
|
|
|
+ return response.json(0, res)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# 忘记密码v3
|
|
|
+class v3resetPwdByCodeView(TemplateView):
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
+ return super(v3resetPwdByCodeView, 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)
|
|
@@ -1140,17 +1451,34 @@ class v2resetPwdByCodeView(TemplateView):
|
|
|
password = base64.b64decode(password)
|
|
|
password = password.decode('utf-8')
|
|
|
password = password[3:-3]
|
|
|
+ print(password)
|
|
|
except Exception as e:
|
|
|
return response.json(111)
|
|
|
+ try:
|
|
|
+ for i in range(1, 4):
|
|
|
+ if i == 1:
|
|
|
+ authcode = base64.b64decode(authcode)
|
|
|
+ authcode = authcode.decode('utf-8')
|
|
|
+ authcode = authcode[1:-1]
|
|
|
+ if i == 2:
|
|
|
+ authcode = base64.b64decode(authcode)
|
|
|
+ authcode = authcode.decode('utf-8')
|
|
|
+ authcode = authcode[2:-2]
|
|
|
+ if i == 3:
|
|
|
+ authcode = base64.b64decode(authcode)
|
|
|
+ authcode = authcode.decode('utf-8')
|
|
|
+ authcode = authcode[3:-3]
|
|
|
+ print(authcode)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(121)
|
|
|
+ if phone is not None:
|
|
|
+ phone = phone.strip()
|
|
|
+ return self.do_phone_pwd_reset(phone, authcode, password, response)
|
|
|
+ elif email is not None:
|
|
|
+ email = email.strip()
|
|
|
+ return self.do_email_pwd_reset(email, authcode, password, response)
|
|
|
else:
|
|
|
- if phone is not None:
|
|
|
- phone = phone.strip()
|
|
|
- return self.do_phone_pwd_reset(phone, authcode, password, response)
|
|
|
- elif email is not None:
|
|
|
- email = email.strip()
|
|
|
- return self.do_email_pwd_reset(email, authcode, password, response)
|
|
|
- else:
|
|
|
- return response.json(444, 'phone')
|
|
|
+ return response.json(444, 'phone')
|
|
|
|
|
|
def do_email_pwd_reset(self, email, authcode, password, response):
|
|
|
data_valid = DataValid()
|
|
@@ -1226,6 +1554,7 @@ class v2resetPwdByCodeView(TemplateView):
|
|
|
return response.json(0, res)
|
|
|
|
|
|
|
|
|
+
|
|
|
# 登录
|
|
|
class v2LoginView(TemplateView):
|
|
|
@method_decorator(csrf_exempt) # @csrf_exempt
|
|
@@ -2503,7 +2832,6 @@ class Image_Code_RegisterView(TemplateView):
|
|
|
valid_code = base64.b64decode(valid_code)
|
|
|
valid_code = valid_code.decode('utf-8')
|
|
|
valid_code = valid_code[3:-3]
|
|
|
- print(valid_code)
|
|
|
except Exception as e:
|
|
|
return response.json(121)
|
|
|
if not userEmail:
|
|
@@ -2541,7 +2869,6 @@ class Image_Code_RegisterView(TemplateView):
|
|
|
"is_active": True,
|
|
|
"user_isValid": True,
|
|
|
}
|
|
|
- print("bbbb")
|
|
|
users = Device_User.objects.create(**create_data)
|
|
|
return response.json(0)
|
|
|
|