|
@@ -2397,13 +2397,14 @@ class generatePictureCodeView(TemplateView):
|
|
|
# 噪点噪线
|
|
|
width = 260
|
|
|
height = 34
|
|
|
- for i in range(5):
|
|
|
+ for i in range(10):
|
|
|
x1 = random.randint(0, width)
|
|
|
x2 = random.randint(0, width)
|
|
|
y1 = random.randint(0, height)
|
|
|
y2 = random.randint(0, height)
|
|
|
draw.line((x1, y1, x2, y2), fill=(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
|
|
|
- for i in range(5):
|
|
|
+
|
|
|
+ for i in range(10):
|
|
|
draw.point([random.randint(0, width), random.randint(0, height)],
|
|
|
fill=(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
|
|
|
x = random.randint(0, width)
|
|
@@ -2421,6 +2422,9 @@ class generatePictureCodeView(TemplateView):
|
|
|
def validates(self, request_dict):
|
|
|
# 页面传过来的uuid
|
|
|
imageCodeId = request_dict.get('imageCodeId', '')
|
|
|
+ response = ResponseObject()
|
|
|
+ if not imageCodeId:
|
|
|
+ return response.json(444)
|
|
|
# 存入redis的key
|
|
|
image_code_id = "image_code_%s" % imageCodeId
|
|
|
"""
|
|
@@ -2446,7 +2450,6 @@ class Image_Code_RegisterView(TemplateView):
|
|
|
return super(Image_Code_RegisterView, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
- print("post进来了吗")
|
|
|
request.encoding = 'utf-8'
|
|
|
request_dict = request.POST
|
|
|
return self.validates(request_dict)
|
|
@@ -2460,17 +2463,16 @@ class Image_Code_RegisterView(TemplateView):
|
|
|
def validates(self,request_dict):
|
|
|
print("__________request_dict:%s" % request_dict)
|
|
|
phone = request_dict.get('phone',None)
|
|
|
- #注释
|
|
|
- #username = request_dict.get('userName',None)
|
|
|
userEmail = request_dict.get('userEmail',None)
|
|
|
password = request_dict.get('userPwd',None)
|
|
|
language = request_dict.get('language',None)
|
|
|
-
|
|
|
#前端传进来的uuid
|
|
|
imageCodeId = request_dict.get('imageCodeId',None)
|
|
|
# 页面输入的验证码
|
|
|
- valid_code = request_dict.get('id_v_code',None)
|
|
|
response = ResponseObject(language)
|
|
|
+ valid_code = request_dict.get('id_v_code', None)
|
|
|
+ if not all([phone, userEmail, password, language, imageCodeId, valid_code]):
|
|
|
+ return response.json(444)
|
|
|
try:
|
|
|
for i in range(1, 4):
|
|
|
if i == 1:
|
|
@@ -2488,51 +2490,66 @@ class Image_Code_RegisterView(TemplateView):
|
|
|
# print(password)
|
|
|
except Exception as e:
|
|
|
return response.json(111)
|
|
|
- else:
|
|
|
- if not userEmail:
|
|
|
- return response.json(105)
|
|
|
- if not password:
|
|
|
- return response.json(109)
|
|
|
- if not phone:
|
|
|
- return response.json(100)
|
|
|
- userEmail = userEmail.strip()
|
|
|
- password = password.strip()
|
|
|
- # 注释
|
|
|
- if userEmail:
|
|
|
- emailValid = Device_User.objects.filter(userEmail=userEmail)
|
|
|
- if emailValid:
|
|
|
- return response.json(103)
|
|
|
- if phone:
|
|
|
- phoneValid = Device_User.objects.filter(phone=phone)
|
|
|
- if phoneValid:
|
|
|
- return response.json(101)
|
|
|
- #根据uuid拼接的key
|
|
|
- image_code_key = "image_code_%s" %imageCodeId
|
|
|
- #判断验证码是否过期
|
|
|
- if image_code_key is None:
|
|
|
- return response.json(120)
|
|
|
- redisObj = RedisObject(db=6)
|
|
|
- #redis里面的验证码
|
|
|
- redis_image_code = redisObj.get_data(key=image_code_key)
|
|
|
- #验证用户输入的验证码和redis中的验证码
|
|
|
- if valid_code.lower()!=redis_image_code.lower():
|
|
|
- return response.json(121)
|
|
|
- # 删除redis中的图片验证码,防止用户使用同一个图片验证码验证多次
|
|
|
- redisObj.del_data(key=image_code_key)
|
|
|
- username = phone
|
|
|
- # #存用户名和密码
|
|
|
- create_data = {
|
|
|
- "phone":phone,
|
|
|
- "username": username,
|
|
|
- "NickName": username,
|
|
|
- "userEmail": userEmail,
|
|
|
- "password": make_password(password),
|
|
|
- "userID": CommonService.getUserID(μs=False, setOTAID=True),
|
|
|
- "is_active": True,
|
|
|
- "user_isValid": True,
|
|
|
- }
|
|
|
- users = Device_User.objects.create(**create_data)
|
|
|
- return response.json(0)
|
|
|
+ try:
|
|
|
+ for i in range(1, 4):
|
|
|
+ if i == 1:
|
|
|
+ valid_code = base64.b64decode(valid_code)
|
|
|
+ valid_code = valid_code.decode('utf-8')
|
|
|
+ valid_code = valid_code[1:-1]
|
|
|
+ if i == 2:
|
|
|
+ valid_code = base64.b64decode(valid_code)
|
|
|
+ valid_code = valid_code.decode('utf-8')
|
|
|
+ valid_code = valid_code[2:-2]
|
|
|
+ if i == 3:
|
|
|
+ valid_code = base64.b64decode(valid_code)
|
|
|
+ valid_code = valid_code.decode('utf-8')
|
|
|
+ valid_code = valid_code[3:-3]
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(121)
|
|
|
+ if not userEmail:
|
|
|
+ return response.json(105)
|
|
|
+ if not password:
|
|
|
+ return response.json(109)
|
|
|
+ if not phone:
|
|
|
+ return response.json(100)
|
|
|
+ userEmail = userEmail.strip()
|
|
|
+ password = password.strip()
|
|
|
+ # 注释
|
|
|
+ if userEmail:
|
|
|
+ emailValid = Device_User.objects.filter(userEmail=userEmail)
|
|
|
+ if emailValid:
|
|
|
+ return response.json(103)
|
|
|
+ if phone:
|
|
|
+ phoneValid = Device_User.objects.filter(phone=phone)
|
|
|
+ if phoneValid:
|
|
|
+ return response.json(101)
|
|
|
+ #根据uuid拼接的key
|
|
|
+ image_code_key = "image_code_%s" %imageCodeId
|
|
|
+ #判断验证码是否过期
|
|
|
+ if image_code_key is None:
|
|
|
+ return response.json(120)
|
|
|
+ redisObj = RedisObject(db=6)
|
|
|
+ #redis里面的验证码
|
|
|
+ redis_image_code = redisObj.get_data(key=image_code_key)
|
|
|
+ #验证用户输入的验证码和redis中的验证码
|
|
|
+ if valid_code.lower()!=redis_image_code.lower():
|
|
|
+ return response.json(121)
|
|
|
+ # 删除redis中的图片验证码,防止用户使用同一个图片验证码验证多次
|
|
|
+ redisObj.del_data(key=image_code_key)
|
|
|
+ username = phone
|
|
|
+ # #存用户名和密码
|
|
|
+ create_data = {
|
|
|
+ "phone":phone,
|
|
|
+ "username": username,
|
|
|
+ "NickName": username,
|
|
|
+ "userEmail": userEmail,
|
|
|
+ "password": make_password(password),
|
|
|
+ "userID": CommonService.getUserID(μs=False, setOTAID=True),
|
|
|
+ "is_active": True,
|
|
|
+ "user_isValid": True,
|
|
|
+ }
|
|
|
+ users = Device_User.objects.create(**create_data)
|
|
|
+ return response.json(0)
|
|
|
|
|
|
|
|
|
|