def post(self, request): result = {} (check_sign_result, check_code, check_msg) = check_sign(request) if not check_sign_result: result['code'] = check_code result['msg'] = check_msg return Response(result) try: mobile = request.POST.get('mobile', '') new_password = request.POST.get('newpwd', '') re_password = request.POST.get('repwd', '') captcha = request.POST.get('captcha', '') if not local_mobile_phone_validator(mobile): msg = u'手机号码不合法。' result['code'] = 234 result['msg'] = msg return Response(result) print new_password,re_password,captcha if new_password and re_password and captcha: try: if new_password != re_password: result['code'] = 241 result['msg'] = u'两次输入的密码不一致。' return Response(result) if not check_password(new_password): result['code'] = 243 result['msg'] = u'密码不符合要求。' return Response(result) userprofile = UserProfile.objects.get(mobile_phone=mobile) try: current_mobile_captcha = Captcha.objects.get(recipient=mobile) if current_mobile_captcha.captcha != captcha: result['code'] = 237 result['msg'] = u'验证码不正确。' return Response(result) if current_mobile_captcha.deadline_time < now(): result['code'] = 235 result['msg'] = u'验证码已过期。' return Response(result) else: current_user = userprofile.user password = make_password(new_password) current_user.password = password current_user.save() result['code'] = 199 result['msg'] = u'重置密码成功。' except Captcha.DoesNotExist: result['code'] = 237 result['msg'] = u'验证码不正确。' return Response(result) except UserProfile.DoesNotExist: result['code'] = 240 result['msg'] = u'不存在使用这个手机号的用户' else: result['code'] = 104 result['msg'] = u'缺少关键参数' return Response(result) except Exception, e: return Response({'msg': u'重置密码异常', 'code': 242})
def post(self, request): result = {} (check_sign_result, check_code, check_msg) = check_sign(request) if not check_sign_result: result['code'] = check_code result['msg'] = check_msg return Response(result) try: mobile = request.POST.get('mobile', '') if not local_mobile_phone_validator(mobile): msg = u'手机号码不合法。' result['code'] = 234 result['msg'] = msg return Response(result) else: try: userprofile = UserProfile.objects.get(mobile_phone=mobile) current_key = CaptchaStore.generate_key() image_url = captcha_image_url(current_key) http_host = request.get_host() img = ''.join(['http://', http_host, image_url]) current_store = CaptchaStore.objects.get(hashkey=current_key) img_value = current_store.challenge result['code'] = 199 result['msg'] = u'获取图片验证码成功' result['img'] = img result['imgvalue'] = img_value except UserProfile.DoesNotExist: result['code'] = 240 result['msg'] = u'不存在使用这个手机号的用户' return Response(result) except Exception, e: traceback.print_exc() return Response({'msg': u'获取图片验证码失败', 'code': 238})
def check_mobile_phone(request): mobile_phone = request.GET.get('mobile_phone', '') result = {} if not local_mobile_phone_validator(mobile_phone): result['error'] = u'无效的手机号码。' return HttpResponse(json.dumps(result), content_type='application/json', status=200) try: UserProfile.objects.get(mobile_phone=mobile_phone) result['error'] = u'此号码已经被注册。' except UserProfile.DoesNotExist: result['error'] = u'' return HttpResponse(json.dumps(result), content_type='application/json', status=200)
def check_register_mobile_phone(request): if request.is_ajax(): mobile_phone = request.GET.get('mobile_phone', '') result = {} if not local_mobile_phone_validator(mobile_phone): if not mobile_phone: result['error']=u'手机号码不能为空!' return HttpResponse(json.dumps(result), content_type='application/json', status=200) result['error'] = u'无效的手机号码。' return HttpResponse(json.dumps(result), content_type='application/json', status=200) try: UserProfile.objects.get(mobile_phone=mobile_phone) except UserProfile.DoesNotExist: result['error'] = u'不是注册过的手机号码' return HttpResponse(json.dumps(result), content_type='application/json', status=200)
def post(self, request): result = {} (check_sign_result, check_code, check_msg) = check_sign(request) if not check_sign_result: result['code'] = check_code result['msg'] = check_msg return Response(result) try: mobile = request.POST.get('mobile', '') if not local_mobile_phone_validator(mobile): msg = u'手机号码不合法。' result['code'] = 234 result['msg'] = msg else: try: userprofile = UserProfile.objects.get(mobile_phone=mobile) msg = u'此号码已经被注册。' result['code'] = 233 result['msg'] = msg except UserProfile.DoesNotExist: new_captcha = random.randint(100000, 999999) current_captcha = Captcha.objects.get_or_create(recipient=mobile)[0] current_captcha.captcha = new_captcha current_captcha.deadline_time = datetime.datetime.now() + datetime.timedelta(minutes=10) current_captcha.save() send_content = u'您的验证码是:%s。请不要把验证码泄露给其他人。' % str(new_captcha) if mobile: (response_code, response_msg) = send_message(mobile, send_content) if response_code == '2': result['code'] = 199 result['msg'] = u'发送成功' result['validity_time'] = '600' else: result['code'] = 232 result['msg'] = u'发送失败' ''' result['code'] = 199 result['msg'] = u'发送成功' result['validity_time'] = '600' ''' return Response(result) except Exception, e: return Response({'msg': u'发送失败', 'code': 232})
def post(self, request): result = {} (check_sign_result, check_code, check_msg) = check_sign(request) if not check_sign_result: result['code'] = check_code result['msg'] = check_msg return Response(result) try: mobile = request.POST.get('mobile', '') if not local_mobile_phone_validator(mobile): msg = u'手机号码不合法。' result['code'] = 234 result['msg'] = msg return Response(result) else: try: userprofile = UserProfile.objects.get(mobile_phone=mobile) new_captcha = random.randint(100000, 999999) current_captcha = Captcha.objects.get_or_create(recipient=mobile)[0] current_captcha.captcha = new_captcha current_captcha.deadline_time = datetime.datetime.now() + datetime.timedelta(minutes=10) current_captcha.save() send_content = u'您的验证码是:%s。请不要把验证码泄露给其他人。' % str(new_captcha) (response_code, response_msg) = send_message(mobile, send_content) if response_code == '2': result['code'] = 199 result['msg'] = u'状态正常,发送验证码到%s' % mobile else: result['code'] = 239 result['msg'] = u'发送失败' except UserProfile.DoesNotExist: result['code'] = 240 result['msg'] = u'不存在使用这个手机号的用户' return Response(result) except Exception, e: return Response({'msg': str(e), 'errcode':1})
def post(self, request): result = {} (check_sign_result, check_code, check_msg) = check_sign(request) if not check_sign_result: result['code'] = check_code result['msg'] = check_msg return Response(result) try: password = request.POST.get('password', '') mobile = request.POST.get('mobile', '') introducer = request.POST.get('introducer', '') verify_code = request.POST.get('verify_code', '') if password and mobile and verify_code: if not local_mobile_phone_validator(mobile): msg = u'手机号码不合法。' result['code'] = 234 result['msg'] = msg return Response(result) if not check_password(password): result['code'] = 243 result['msg'] = u'密码不符合要求。' return Response(result) if User.objects.filter(username=mobile).count() != 0: result['code'] = 233 result['msg'] = u'此号码已经被注册。' return Response(result) try: userprofile = UserProfile.objects.get(mobile_phone=mobile) result['code'] = 233 result['msg'] = u'此号码已经被注册。' except UserProfile.DoesNotExist: try: current_mobile_captcha = Captcha.objects.get(recipient=mobile) if current_mobile_captcha.deadline_time < now(): result['code'] = 235 result['msg'] = u'验证码已过期。' return Response(result) if current_mobile_captcha.captcha != verify_code: result['code'] = 237 result['msg'] = u'验证码不正确。' else: new_user = User.objects.create(username=mobile, password=make_password(password)) try: current_userprofile = new_user.userprofile current_userprofile.mobile_phone = mobile current_userprofile.introducer = introducer except UserProfile.DoesNotExist: current_userprofile = UserProfile.objects.create(user=new_user, mobile_phone=mobile) if request.META.has_key('HTTP_X_FORWARDED_FOR'): current_ip = request.META['HTTP_X_FORWARDED_FOR'] else: current_ip = request.META['REMOTE_ADDR'] current_userprofile.register_ip = current_ip current_userprofile.save() result['code'] = 199 result['msg'] = u'注册成功。' except Captcha.DoesNotExist: result['code'] = 237 result['msg'] = u'验证码不正确。' return Response(result) except Exception, e: print e return Response({'msg': u'注册失败', 'code': 236})