def register(self, request, *args, **kwargs): print('注册请求') uname = request.data['username'] user = User.objects.filter(username=uname) if user: return MyResponse(400, '用户名已存在') user_ser = self.create(request, *args, **kwargs) return MyResponse(200, '注册成功', results=user_ser.data)
def get(self, request, *args, **kwargs): uname = request.query_params['username'] pwd = request.query_params['password'] print(uname, pwd) user = User.objects.filter(username=uname, password=pwd).first() user_ser = UserModelSerializer(user) print('登陆', user_ser, type(user_ser)) if user: return MyResponse(200, True, results=user_ser.data) return MyResponse(401, False)
def login(self, request, *args, **kwargs): input_pwd = request.data['password'] print(22222, input_pwd) try: user_ser = self.retrieve(request, *args, **kwargs) except: return MyResponse(400, '用户名或密码错误') pwd = user_ser.data['password'] if input_pwd == pwd: return MyResponse(200, '登陆成功', results=user_ser.data) return MyResponse(400, '用户名或密码错误')
def get(self, request): print('获取验证码请求') # username = request.query_params['username'] username = request.query_params.get('username') user = check_user(username) if user: self.user_id = user.id print('验证id', self.user_id) gt = GeetestLib(pc_geetest_id, pc_geetest_key) self.status = gt.pre_process(self.user_id) print(27, self.status) response_str = gt.get_response_str() print(29, response_str) return MyResponse(200, True, response_str) return MyResponse(400, '用户不存在')
def post(self, request, *args, **kwargs): user_data = request.data user = UserModelSerializer(data=user_data) print('注册用户', user, type(user)) user.is_valid(raise_exception=True) user.save() return MyResponse(200, '注册用户成功')
def post(self, request): print(222222) gt = GeetestLib(pc_geetest_id, pc_geetest_key) challenge = request.POST.get(gt.FN_CHALLENGE, '') validate = request.POST.get(gt.FN_VALIDATE, '') seccode = request.POST.get(gt.FN_SECCODE, '') print(333333) uname = request.data['username'] # if self.status: if uname: print(uname) result = gt.success_validate(challenge, validate, seccode, self.user_id) re = {"status": "success"} else: result = gt.failback_validate(challenge, validate, seccode) re = {"status": "fail"} print(44, result) # result = "<html><body><h1>登录成功</h1></body></html>" if result else "<html><body><h1>登录失败</h1></body></html>" # result = {"status": "success"} if result else {"status": "fail"} print(47, re) return MyResponse(re)
def delete(self, request, *args, **kwargs): uname = kwargs.get('uname') user = User.objects.filter(username=uname)[0] user.delete() return MyResponse(200, True)
def post(self, request, *args, **kwargs): return MyResponse('用户访问')