def post(self, request): # return JsonResponse(ref.set(400, "用户或密码错误")) userInfo = json.loads(request.POST.get("data")) print(userInfo, "uuuuuu") isUser = authenticate(username=userInfo["username"], password=userInfo["password"]) if isUser: login(request, isUser) tk = Token().encodejwt(isUser.username) cache.set(str(tk), isUser.username, 60 * 60) data = {"token": tk} data.update(ref.code(200)) return JsonResponse(data) else: return JsonResponse(ref.set(400, "用户或密码错误"))
def dataStorage(cls, newUser, data, num): msgList = [] #"1"DNS多对一 "2" DNS多对多 "5" SQL多对一" 6" SQL多对多 regExJump = { 1: { "jumptarget": newUser.target, "is_jump": False }, 2: { "jumptarget": data["url"], "is_jump": False }, 5: { "jumptarget": newUser.target, "is_jump": True }, 6: { "jumptarget": data["url"], "is_jump": True }, } for one in data["textarea"]: try: temp = re.split("\.", one)[-2:] newOne = "www." + temp[0].strip() + "." + temp[1].strip() except Exception as f: msg = "{}无效域名,添加失败".format(one) msgList.append(msg) continue newJ = Jump.objects.filter(name=newOne) if newJ: newId = newJ.first().relationship_id if newId != data["id"]: other = newJ.first().relationship.username otherMsg = str(other)[:2] + "***" + str(other)[-2:] msg = "警告:{},用户:{}已添加,操作失败".format(one, otherMsg) msgList.append(msg) continue _num = int(data["mode"]) if _num in [5, 6]: isJump = True else: isJump = False newJ.update(name=newOne, jumptarget=regExJump[num]["jumptarget"], is_jump=isJump, relationship_id=data["id"]) else: oneUserObj = User.objects.filter(id=data["id"]).first() JumpObjNum = len(oneUserObj.jump_target.all()) print("oneUserObj.number", oneUserObj.number, type(oneUserObj.number)) if (oneUserObj.number - JumpObjNum) <= 0: raise MyException(ref.set(403, "数量不足,无权添加")) Jump.objects.create(name=newOne, jumptarget=regExJump[num]["jumptarget"], is_jump=regExJump[num]["is_jump"], relationship_id=data["id"]) if msgList: raise MyException(ref.set(403, msgList)) return True