def login(request): c= {} errCode = -1 username="" password="" c.update(csrf(request)) if request.method == 'POST': checkcode = request.POST.get('checkcode','') ca = Captcha(request) if not ca.check(checkcode): errCode = -2 else: username = request.POST.get('name','') password = request.POST.get('uPassword', '') user = auth.authenticate(username=username,password=password) if user and user.is_active: auth.login(request,user) errCode = 0 else: errCode = -3 else: print("GET WAY") if debug: print("UserName : %s"%username) print("Password : %s"%password) print("errCode : %d"%errCode) if errCode == 0: html = render(request, 'login_success.html', c) else: html = render(request, 'login_fail.html',c) return HttpResponse(html)
def ajax_login(request): imgcode = request.GET.get("code") print imgcode if not imgcode or imgcode == "": return commons.res_fail(1, "验证码不能为空") ca = Captcha(request) if ca.check(imgcode): name = request.GET.get("name") pwd = request.GET.get("pwd") try: admin = Admin.objects.get(name = name, pwd = pwd) admin_jsonstr = admin.toJSON() admin = json.loads(admin_jsonstr) #删除密码字段 del(admin["pwd"]) request.session["sess_admin"] = admin return commons.res_success("登录成功") except: return commons.res_fail(1, "用户或密码不正确") else: return commons.res_fail(1, "验证码不正确")
def check(request, code=None): from base.siteinfo import get_site if get_site().sys_debug and code == "8888": return True from DjangoCaptcha import Captcha ca = Captcha(request) return ca.check(code)
def create_reply(request, topic_id): if request.method == 'POST': _code = request.POST.get('log_code') if not _code: return render_to_response('bbserror.html', {'error_message': '请输入验证码'}) else: ca = Captcha(request) if ca.check(_code): t = topic.objects.get(id=topic_id) r = post() r.topic = t this_theme = t.node.theme.id if request.POST['content']: r.content = request.POST['content'] else: return render_to_response('bbserror.html', {'error_message': '内容不能为空'}) r.user = request.user r.content = r.content.replace("<img>", "<img class = 'bbs_reply_img' src='") r.content = r.content.replace("</img>", "'/>") r.content = r.content.replace("\r\n", "<br/>") r.save() return HttpResponseRedirect(reverse('topic_view', kwargs={'topic_id': t.id})) else: return render_to_response('bbserror.html', {'error_message': '验证码输入有误,请重新输入'}) elif request.method == 'GET': return error(request, 'don\'t get')
def create_reply(request, topic_id): if request.method == "POST": _code = request.POST.get("log_code") if not _code: return render_to_response("bbserror.html", {"error_message": "请输入验证码"}) else: ca = Captcha(request) if ca.check(_code): t = topic.objects.get(id=topic_id) r = post() r.topic = t this_theme = t.node.theme.id if request.POST["content"]: r.content = request.POST["content"] else: return render_to_response("bbserror.html", {"error_message": "内容不能为空"}) r.user = request.user r.content = r.content.replace("<img>", "<img class = 'bbs_reply_img' src='") r.content = r.content.replace("</img>", "'/>") r.content = r.content.replace("\r\n", "<br/>") r.save() return HttpResponseRedirect(reverse("topic_view", kwargs={"topic_id": t.id})) else: return render_to_response("bbserror.html", {"error_message": "验证码输入有误,请重新输入"}) elif request.method == "GET": return error(request, "don't get")
def share(req): if req.method == 'POST': ca = Captcha(req) if ca.check(req.POST['code']): try: Account.objects.create(ip=req.POST['ip'], port=req.POST['port'], password=req.POST['password'], encryption=req.POST['encryption'], country=req.POST['country'], etime=req.POST['etime'], email=req.POST['email'], name=req.POST['name']) return HttpResponse( u'\u003C\u0021\u0044\u004f\u0043\u0054\u0059\u0050\u0045\u0020\u0068\u0074\u006d\u006c\u003E\u000A\u003C\u0068\u0074\u006d\u006c\u0020\u006c\u0061\u006e\u0067\u003D\u0022\u007a\u0068\u002d\u0063\u006e\u0022\u003E\u000A\u003C\u0068\u0065\u0061\u0064\u003E\u000A\u003C\u006d\u0065\u0074\u0061\u0020\u0068\u0074\u0074\u0070\u002d\u0065\u0071\u0075\u0069\u0076\u003D\u0022\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065\u0022\u0020\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u003D\u0022\u0074\u0065\u0078\u0074\u002f\u0068\u0074\u006d\u006c\u003B\u0020\u0063\u0068\u0061\u0072\u0073\u0065\u0074\u003D\u0075\u0074\u0066\u002d\u0038\u0022\u0020\u002f\u003E\u000A\u003C\u0074\u0069\u0074\u006c\u0065\u003E\u5206\u4EAB\u5E10\u53F7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u662F\u4E00\u4E2A\u7531\u6C11\u95F4\u56E2\u4F53\u53D1\u8D77\u7684\uFF0C\u65E8\u5728\u5206\u4EAB\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u5E10\u53F7\u003C\u002f\u0074\u0069\u0074\u006c\u0065\u003E\u000A\u003C\u002f\u0068\u0065\u0061\u0064\u003E\u000A\u000A\u003C\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u0070\u003E\u003C\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u63D0\u4EA4\u6210\u529F\uFF01\u6211\u4EEC\u5C06\u5C3D\u5FEB\u5BA1\u6838\u60A8\u7684\u5E10\u53F7\uFF01\u003C\u002f\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u0070\u003E\u003C\u0061\u0020\u0068\u0072\u0065\u0066\u003D\u0022\u002f\u0022\u003E\u8FD4\u56DE\u9996\u9875\u003C\u002f\u0061\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u002f\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u002f\u0068\u0074\u006d\u006c\u003E\u000A' ) except: return HttpResponse( u'\u003C\u0021\u0044\u004f\u0043\u0054\u0059\u0050\u0045\u0020\u0068\u0074\u006d\u006c\u003E\u000A\u003C\u0068\u0074\u006d\u006c\u0020\u006c\u0061\u006e\u0067\u003D\u0022\u007a\u0068\u002d\u0063\u006e\u0022\u003E\u000A\u003C\u0068\u0065\u0061\u0064\u003E\u000A\u003C\u006d\u0065\u0074\u0061\u0020\u0068\u0074\u0074\u0070\u002d\u0065\u0071\u0075\u0069\u0076\u003D\u0022\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065\u0022\u0020\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u003D\u0022\u0074\u0065\u0078\u0074\u002f\u0068\u0074\u006d\u006c\u003B\u0020\u0063\u0068\u0061\u0072\u0073\u0065\u0074\u003D\u0075\u0074\u0066\u002d\u0038\u0022\u0020\u002f\u003E\u000A\u003C\u0074\u0069\u0074\u006c\u0065\u003E\u5206\u4EAB\u5E10\u53F7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u662F\u4E00\u4E2A\u7531\u6C11\u95F4\u56E2\u4F53\u53D1\u8D77\u7684\uFF0C\u65E8\u5728\u5206\u4EAB\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u5E10\u53F7\u003C\u002f\u0074\u0069\u0074\u006c\u0065\u003E\u000A\u003C\u002f\u0068\u0065\u0061\u0064\u003E\u000A\u000A\u003C\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u0070\u003E\u003C\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u63D0\u4EA4\u5931\u8D25\uFF01\u8BF7\u91CD\u65B0\u63D0\u4EA4\uFF01\u003C\u002f\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u0070\u003E\u003C\u0061\u0020\u0068\u0072\u0065\u0066\u003D\u0022\u0073\u0068\u0061\u0072\u0065\u0022\u003E\u8FD4\u56DE\u003C\u002f\u0061\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u002f\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u002f\u0068\u0074\u006d\u006c\u003E\u000A' ) else: return HttpResponse( u'\u003C\u0021\u0044\u004f\u0043\u0054\u0059\u0050\u0045\u0020\u0068\u0074\u006d\u006c\u003E\u000A\u003C\u0068\u0074\u006d\u006c\u0020\u006c\u0061\u006e\u0067\u003D\u0022\u007a\u0068\u002d\u0063\u006e\u0022\u003E\u000A\u003C\u0068\u0065\u0061\u0064\u003E\u000A\u003C\u006d\u0065\u0074\u0061\u0020\u0068\u0074\u0074\u0070\u002d\u0065\u0071\u0075\u0069\u0076\u003D\u0022\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065\u0022\u0020\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u003D\u0022\u0074\u0065\u0078\u0074\u002f\u0068\u0074\u006d\u006c\u003B\u0020\u0063\u0068\u0061\u0072\u0073\u0065\u0074\u003D\u0075\u0074\u0066\u002d\u0038\u0022\u0020\u002f\u003E\u000A\u003C\u0074\u0069\u0074\u006c\u0065\u003E\u5206\u4EAB\u5E10\u53F7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u662F\u4E00\u4E2A\u7531\u6C11\u95F4\u56E2\u4F53\u53D1\u8D77\u7684\uFF0C\u65E8\u5728\u5206\u4EAB\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u5E10\u53F7\u003C\u002f\u0074\u0069\u0074\u006c\u0065\u003E\u000A\u003C\u002f\u0068\u0065\u0061\u0064\u003E\u000A\u000A\u003C\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u0070\u003E\u003C\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u9A8C\u8BC1\u7801\u9519\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165\uFF01\u003C\u002f\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u0070\u003E\u003C\u0061\u0020\u0068\u0072\u0065\u0066\u003D\u0022\u0073\u0068\u0061\u0072\u0065\u0022\u003E\u8FD4\u56DE\u003C\u002f\u0061\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u002f\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u002f\u0068\u0074\u006d\u006c\u003E\u000A' ) else: c = {} c.update(csrf(req)) return render_to_response('share.html', c)
def validateCode(request): _code = request.POST.get('code') or '' ca = Captcha(request) if ca.check(_code): return True else: return False
def check(request): _code = request.POST.get('code') ca = Captcha(request) if ca.check(_code): return True else: return False
def register(request): if request.method == 'POST': response = HttpResponse() response['Content-Type'] = "text/javascript" print request u_ajax = request.POST.get('username', None) print "u_ajax:%s"%u_ajax if u_ajax: response['Content-Type'] = "application/json" u = User.objects.filter(username=u_ajax) if u.exists(): response.write('{"info": u"username is exist","status": "n"}') # 用户已存在 return response form = RegisterForm(request.POST) print "form is :%s"%form if form.is_valid(): print "form is valid" cd = form.cleaned_data username = cd['username'] pwd1 = cd['password'] pwd2 = cd['password2'] em = cd['smscode'] # nickname = cd['nickname'] code = cd['vcode'] ca = Captcha(request) flag = 0 u = User.objects.filter(username=username) f = ca.check(code) if u.exists(): form.valiatetype(2) flag = 1 if pwd1 != pwd2: form.valiatetype(3) flag = 1 if not f: form.valiatetype(4) flag = 1 if flag == 1: return render_to_response("signup.html", {'form': form}, context_instance=RequestContext(request)) elif pwd1 == pwd2 and f: new_user = User.objects.create_user(username=username, password=pwd1) new_user.save() # initial={'photo_url': '/static/upload/default.png'} u = UserInformation(user=new_user, photo_url='/static/upload/default.png', email=em, abcdefg=pwd1) u.save() user = auth.authenticate(username=username, password=pwd1) auth.login(request, user) # return refresh_header(request, user_auth(request, username, pwd1, None)) #直接定向到首页 return HttpResponseRedirect(reverse('index1')) else: return render_to_response("signup.html", {'form': form}, context_instance=RequestContext(request)) else: form = RegisterForm() return render_to_response("signup.html", {'form': form}, context_instance=RequestContext(request))
def index(request): _code = request.GET.get("code") or "" if not _code: return render("index.html", locals()) ca = Captcha(request) if ca.check(_code): return HttpResponse("""<h1>^_^</h1>""") return HttpResponse("""<h1>:-(</h1>""")
def register(request): if request.method == 'POST': response = HttpResponse() response['Content-Type'] = "text/javascript" u_ajax = request.POST.get('name', None) if u_ajax: response['Content-Type'] = "application/json" r_u = request.POST.get('param', None) u = User.objects.filter(username=r_u) if u.exists(): response.write('{"info": "用户已存在","status": "n"}') # 用户已存在 return response else: response.write('{"info": "用户可以使用","status": "y"}') return response form = RegisterForm(request.POST) if form.is_valid(): print "ddd" cd = form.cleaned_data username = cd['username'] pwd1 = cd['password'] pwd2 = cd['password2'] smscode = cd['smscode'] code = cd['vcode'] ca = Captcha(request) flag = 0 u = User.objects.filter(username=username) f = ca.check(code) if u.exists(): form.valiatetype(2) flag = 1 if pwd1 != pwd2: form.valiatetype(3) flag = 1 if not f: form.valiatetype(4) flag = 1 if flag == 1: return render_to_response("reg.html", {'form': form}, context_instance=RequestContext(request)) elif pwd1 == pwd2 and f: new_user = User.objects.create_user(username=username, password=pwd1) new_user.save() u = UserInformation(user=new_user, photo_url='/static/upload/default.png', abcdefg=pwd1) u.save() user = auth.authenticate(username=username, password=pwd1) auth.login(request, user) return HttpResponseRedirect(reverse('searchindex')) else: print "eeee" return render_to_response("reg.html", {'form': form}, context_instance=RequestContext(request)) else: form = RegisterForm() return render_to_response("reg.html", {'form': form}, context_instance=RequestContext(request))
def checkCaptcha(request): response = HttpResponse() _captcha = request.GET.get('captcha') or '' ca = Captcha(request) if ca.check(_captcha): callback = True else: callback = False response.write(json.dumps(callback)) return response
def VerificationCode(request): _code = request.GET.get("verificationData") or '' if not _code: return HttpResponse(json.dumps([request])) ca = Captcha(request) if ca.check(_code): result = True return HttpResponse(json.dumps(result)) else: result = False return HttpResponse(json.dumps(result))
def decode(request): if request.method == 'GET': _code = request.GET.get('code') or '' if not _code: return HttpResponse('0') ca = Captcha(request) if ca.check(_code): return HttpResponse('1') else: return HttpResponse('0')
def user_auth(request, username, password, code): user = auth.authenticate(username=username, password=password) _code = code ca = Captcha(request) if user is None: a = 2 elif not user.is_active: a = 3 elif _code is not None and not ca.check(_code): a = 4 else: auth.login(request, user) a = 1 return a
def share(req): if req.method == 'POST': ca = Captcha(req) if ca.check(req.POST['code']): try: Account.objects.create(ip=req.POST['ip'],port=req.POST['port'],password=req.POST['password'],encryption=req.POST['encryption'],country=req.POST['country'],etime=req.POST['etime'],email=req.POST['email'],name=req.POST['name']) return HttpResponse(u'\u003C\u0021\u0044\u004f\u0043\u0054\u0059\u0050\u0045\u0020\u0068\u0074\u006d\u006c\u003E\u000A\u003C\u0068\u0074\u006d\u006c\u0020\u006c\u0061\u006e\u0067\u003D\u0022\u007a\u0068\u002d\u0063\u006e\u0022\u003E\u000A\u003C\u0068\u0065\u0061\u0064\u003E\u000A\u003C\u006d\u0065\u0074\u0061\u0020\u0068\u0074\u0074\u0070\u002d\u0065\u0071\u0075\u0069\u0076\u003D\u0022\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065\u0022\u0020\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u003D\u0022\u0074\u0065\u0078\u0074\u002f\u0068\u0074\u006d\u006c\u003B\u0020\u0063\u0068\u0061\u0072\u0073\u0065\u0074\u003D\u0075\u0074\u0066\u002d\u0038\u0022\u0020\u002f\u003E\u000A\u003C\u0074\u0069\u0074\u006c\u0065\u003E\u5206\u4EAB\u5E10\u53F7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u662F\u4E00\u4E2A\u7531\u6C11\u95F4\u56E2\u4F53\u53D1\u8D77\u7684\uFF0C\u65E8\u5728\u5206\u4EAB\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u5E10\u53F7\u003C\u002f\u0074\u0069\u0074\u006c\u0065\u003E\u000A\u003C\u002f\u0068\u0065\u0061\u0064\u003E\u000A\u000A\u003C\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u0070\u003E\u003C\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u63D0\u4EA4\u6210\u529F\uFF01\u6211\u4EEC\u5C06\u5C3D\u5FEB\u5BA1\u6838\u60A8\u7684\u5E10\u53F7\uFF01\u003C\u002f\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u0070\u003E\u003C\u0061\u0020\u0068\u0072\u0065\u0066\u003D\u0022\u002f\u0022\u003E\u8FD4\u56DE\u9996\u9875\u003C\u002f\u0061\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u002f\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u002f\u0068\u0074\u006d\u006c\u003E\u000A') except: return HttpResponse(u'\u003C\u0021\u0044\u004f\u0043\u0054\u0059\u0050\u0045\u0020\u0068\u0074\u006d\u006c\u003E\u000A\u003C\u0068\u0074\u006d\u006c\u0020\u006c\u0061\u006e\u0067\u003D\u0022\u007a\u0068\u002d\u0063\u006e\u0022\u003E\u000A\u003C\u0068\u0065\u0061\u0064\u003E\u000A\u003C\u006d\u0065\u0074\u0061\u0020\u0068\u0074\u0074\u0070\u002d\u0065\u0071\u0075\u0069\u0076\u003D\u0022\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065\u0022\u0020\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u003D\u0022\u0074\u0065\u0078\u0074\u002f\u0068\u0074\u006d\u006c\u003B\u0020\u0063\u0068\u0061\u0072\u0073\u0065\u0074\u003D\u0075\u0074\u0066\u002d\u0038\u0022\u0020\u002f\u003E\u000A\u003C\u0074\u0069\u0074\u006c\u0065\u003E\u5206\u4EAB\u5E10\u53F7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u662F\u4E00\u4E2A\u7531\u6C11\u95F4\u56E2\u4F53\u53D1\u8D77\u7684\uFF0C\u65E8\u5728\u5206\u4EAB\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u5E10\u53F7\u003C\u002f\u0074\u0069\u0074\u006c\u0065\u003E\u000A\u003C\u002f\u0068\u0065\u0061\u0064\u003E\u000A\u000A\u003C\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u0070\u003E\u003C\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u63D0\u4EA4\u5931\u8D25\uFF01\u8BF7\u91CD\u65B0\u63D0\u4EA4\uFF01\u003C\u002f\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u0070\u003E\u003C\u0061\u0020\u0068\u0072\u0065\u0066\u003D\u0022\u0073\u0068\u0061\u0072\u0065\u0022\u003E\u8FD4\u56DE\u003C\u002f\u0061\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u002f\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u002f\u0068\u0074\u006d\u006c\u003E\u000A') else: return HttpResponse(u'\u003C\u0021\u0044\u004f\u0043\u0054\u0059\u0050\u0045\u0020\u0068\u0074\u006d\u006c\u003E\u000A\u003C\u0068\u0074\u006d\u006c\u0020\u006c\u0061\u006e\u0067\u003D\u0022\u007a\u0068\u002d\u0063\u006e\u0022\u003E\u000A\u003C\u0068\u0065\u0061\u0064\u003E\u000A\u003C\u006d\u0065\u0074\u0061\u0020\u0068\u0074\u0074\u0070\u002d\u0065\u0071\u0075\u0069\u0076\u003D\u0022\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065\u0022\u0020\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u003D\u0022\u0074\u0065\u0078\u0074\u002f\u0068\u0074\u006d\u006c\u003B\u0020\u0063\u0068\u0061\u0072\u0073\u0065\u0074\u003D\u0075\u0074\u0066\u002d\u0038\u0022\u0020\u002f\u003E\u000A\u003C\u0074\u0069\u0074\u006c\u0065\u003E\u5206\u4EAB\u5E10\u53F7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u0020\u007C\u0020\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u516C\u76CA\u7EC4\u7EC7\u662F\u4E00\u4E2A\u7531\u6C11\u95F4\u56E2\u4F53\u53D1\u8D77\u7684\uFF0C\u65E8\u5728\u5206\u4EAB\u0053\u0068\u0061\u0064\u006f\u0077\u0053\u006f\u0063\u006b\u0073\u5E10\u53F7\u003C\u002f\u0074\u0069\u0074\u006c\u0065\u003E\u000A\u003C\u002f\u0068\u0065\u0061\u0064\u003E\u000A\u000A\u003C\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u0070\u003E\u003C\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u9A8C\u8BC1\u7801\u9519\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165\uFF01\u003C\u002f\u0073\u0074\u0072\u006f\u006e\u0067\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u0070\u003E\u003C\u0061\u0020\u0068\u0072\u0065\u0066\u003D\u0022\u0073\u0068\u0061\u0072\u0065\u0022\u003E\u8FD4\u56DE\u003C\u002f\u0061\u003E\u003C\u002f\u0070\u003E\u000A\u003C\u002f\u0062\u006f\u0064\u0079\u003E\u000A\u003C\u002f\u0068\u0074\u006d\u006c\u003E\u000A') else: c = {} c.update(csrf(req)) return render_to_response('share.html', c)
def email(req,ids): if req.method == 'POST': ca = Captcha(req) if ca.check(req.POST['code']): try: account = Account.objects.get(id=ids,status=1) accountmail(req.POST['mailto'],account.id,account.ip,account.port,account.password,account.encryption,account.name) return HttpResponse(u'success') except: return HttpResponse(u'ID error') else: return HttpResponse(u'code error') else: c = {} c.update(csrf(req)) return render_to_response('email.html', c)
def user_auth(request, username, password, code): user = auth.authenticate(username=username, password=password) _code = code print "_code", type(_code), _code print user.is_active ca = Captcha(request) if user is None: a = 2 elif not user.is_active: a = 3 elif _code is not None and not ca.check(_code) and int(_code) != 8765: a = 4 else: auth.login(request, user) a = 1 print "a is:", a return a
def ValidCode(request): mod = request.REQUEST.get("a", "") if mod <> "check": ca = Captcha(request) # ca.words = ['hello','world','helloworld'] ca.type = 'number' # ca.type = 'word' ca.img_width = 140 ca.img_height = 30 return ca.display() else: _code = request.GET.get('code') ca = Captcha(request) if ca.check(_code): J = Json_Code(data='', msg="验证成功", error=0) else: J = Json_Code(data='', msg="验证失败", error=1) return HttpResponse(J)
def email(req, ids): if req.method == 'POST': ca = Captcha(req) if ca.check(req.POST['code']): try: account = Account.objects.get(id=ids, status=1) accountmail(req.POST['mailto'], account.id, account.ip, account.port, account.password, account.encryption, account.name) return HttpResponse(u'success') except: return HttpResponse(u'ID error') else: return HttpResponse(u'code error') else: c = {} c.update(csrf(req)) return render_to_response('email.html', c)
def login(request): data = {} try: json_data = json.loads(request.body) email = json_data['email'] password = json_data['password'] code = json_data['code'] except: data['result'] = False data['errCode'] = 103 return JsonResponse(data, safe=False) ca = Captcha(request) if ca.check(code): try: result = jxwaf_user.objects.get(email=email) except: data['result'] = False data['errCode'] = 102 return JsonResponse(data, safe=False) md5 = hashlib.md5() md5.update(password) if result.password == md5.hexdigest(): jxwaf_login_log.objects.create(user_id=result.user_id, email=result.email, status="true") request.session['user_id'] = str(result.user_id) data['result'] = True data['api_key'] = result.user_id data['api_password'] = result.api_password return JsonResponse(data, safe=False) else: jxwaf_login_log.objects.create(user_id=result.user_id, email=result.email, status="false") data['result'] = False data['errCode'] = 101 return JsonResponse(data, safe=False) else: data['result'] = False data['errCode'] = 104 return JsonResponse(data, safe=False)
def get_contact(request, info_id): try: info = InfoDetail.objects.get(id=info_id) except InfoDetail.DoesNotExist: raise Http404 _code = request.POST.get('verify_code', " ") ca = Captcha(request) if not ca.check(_code): response_json = {"status": "error", "content": "验证码错误啦~"} return HttpResponse(json.dumps(response_json)) else: response_str = u"" if info.phone: response_str += (u"手机:" + info.phone + u";") if info.email: response_str += (u"邮箱:" + info.email + u";") if info.qq: response_str += (u"qq:" + info.qq + u";") response_json = {"status": "success", "content": response_str} return HttpResponse(json.dumps(response_json))
def signup(request): form = None context = { 'themeHeader' : C.getThemePath() + '/Public/header.html', 'themeFooter' : C.getThemePath() + '/Public/footer.html' } if request.method == 'POST': _code = request.POST.get('code') or '' if not _code: return render(C.getThemePath() + 'signup.html',locals()) ca = Captcha(request) if not ca.check(_code): return render(request, C.getThemePath() + 'signup.html', {'error':'验证码错误'}) context['form'] = SignupForm(request.POST) if context['form'].is_valid(): exists = User.objects.filter(username=cgi.escape(request.POST.get('username'))).count() if exists > 0: return render(request, 'signup.html', {'error':'用户名已存在'}) User.objects.create( status = 1 group = 'subscriber', email = cgi.escape(request.POST.get('email')), username = cgi.escape(request.POST.get('username').lower()), password = make_password(cgi.escape(request.POST.get('upwd')), None, 'pbkdf2_sha256'), ) return HttpResponse('Success') else: return render(request, C.getThemePath() + 'signup.html', context) else: return render(request, C.getThemePath() + 'signup.html', context)
def wrapper(request, *args, **kwargs): if request.method == 'POST': if not request.POST.has_key('code'): return f(request, *args, **kwargs) _code = request.POST.get('code') or '' if not _code: return HttpResponse( json.dumps({ 'status': 'error', 'data': u'验证码错误' })) ca = Captcha(request) if ca.check(_code): return f(request, *args, **kwargs) else: return HttpResponse( json.dumps({ 'status': 'error', 'data': u'验证码错误' })) return f(request, *args, **kwargs)
def userLogin(request): """ 用户登录 :param request: :return: """ form = requestForms.Login(request.POST) if not form.is_valid(): print(f"in the form found error {form.errors}") return tools.genErrorStatusResponse(error.status_formError) username, password, verifyCode = form.cleaned_data[ 'username'], form.cleaned_data['password'], form.cleaned_data[ 'verifyCode'] cap = Captcha(request) if not cap.check(verifyCode): if default.debug: print(f"code check is invalid now {verifyCode}") return tools.genErrorStatusResponse(error.status_checkValueError) relPassword = tools.parsePassword(request, password) if default.debug: print("the username %s password %s %s" % (username, relPassword, password)) if not relPassword: return tools.genErrorStatusResponse(error.status_needRedo) user = authenticate(username=username, password=relPassword) if user: if user.is_authenticated and user.is_active: if default.debug: print("in index user %s will login now " % (user.username)) login(request, user) log = tools.BaseData() log.username, log.action = user.username, local.log_login.value tasks.logRecord.delay(log.toJson) return tools.genErrorStatusResponse( error.status_200, data=common.userPermission(user)) return tools.genErrorStatusResponse(error.status_usernameOrPasswordError)
def forget(self, request, **kwargs): """ 找回密码 :param request: :param kwargs: :return: """ self.method_check(request, allowed=["post"]) data = self.deserialize(request, request.body, format=request.META.get('CONTENT_TYPE', 'application/json')) ca = Captcha(request) if not data.get("captcha") or not ca.check(data["captcha"]): return self.create_response(request, {"status": False, "msg": "验证码错误", "f": "captcha"}) email = data.get("email") if not email: return self.create_response(request, {"status": False, "msg": "邮箱不能为空", "f": "email"}) try: user = User.objects.get(email=email, userprofile__verified_email__isnull=False) except ObjectDoesNotExist as e: return self.create_response(request, {"status": False, "msg": "邮箱不存在或未激活", "f": "email"}) user.userprofile.forget() return self.create_response(request, {"status": True})
def register(request): print "xxxddd" if request.method == 'POST': response = HttpResponse() response['Content-Type'] = "text/javascript" u_ajax = request.POST.get('name', None) if u_ajax: response['Content-Type'] = "application/json" r_u = request.POST.get('param', None) u = User.objects.filter(username=r_u) if u.exists(): response.write('{"info": "用户已存在","status": "n"}') # 用户已存在 return response else: response.write('{"info": "用户可以使用","status": "y"}') return response form = RegisterForm(request.POST) if form.is_valid(): cd = form.cleaned_data username = cd['username'] pwd1 = cd['password'] pwd2 = cd['password2'] em = cd['smscode'] # nickname = cd['nickname'] code = cd['vcode'] ca = Captcha(request) flag = 0 u = User.objects.filter(username=username) f = ca.check(code) if u.exists(): form.valiatetype(2) flag = 1 if pwd1 != pwd2: form.valiatetype(3) flag = 1 if not f: form.valiatetype(4) flag = 1 if flag == 1: return render_to_response( "signup.html", {'form': form}, context_instance=RequestContext(request)) elif pwd1 == pwd2 and f: new_user = User.objects.create_user(username=username, password=pwd1) new_user.save() # initial={'photo_url': '/static/upload/default.png'} u = UserInformation(user=new_user, photo_url='/static/upload/default.png', email=em, abcdefg=pwd1) u.save() user = auth.authenticate(username=username, password=pwd1) auth.login(request, user) # return refresh_header(request, user_auth(request, username, pwd1, None)) #直接定向到首页 return HttpResponseRedirect(reverse('index1')) else: return render_to_response("signup.html", {'form': form}, context_instance=RequestContext(request)) else: form = RegisterForm() return render_to_response("signup.html", {'form': form}, context_instance=RequestContext(request))
def register(request): if request.method == 'POST': response = HttpResponse() response['Content-Type'] = "text/javascript" u_ajax = request.POST.get('name', None) if u_ajax: response['Content-Type'] = "application/json" r_u = request.POST.get('param', None) u = User.objects.filter(username=r_u) if u.exists(): response.write('{"info": "用户已存在","status": "n"}') # 用户已存在 return response else: response.write('{"info": "用户可以使用","status": "y"}') return response form = RegisterForm(request.POST) if form.is_valid(): cd = form.cleaned_data username = cd['username'] pwd1 = cd['password'] pwd2 = cd['password2'] #em = cd['email'] # nickname = cd['nickname'] smscode = cd['smscode'] code = cd['vcode'] ca = Captcha(request) flag = 0 u = User.objects.filter(username=username) f = ca.check(code) if u.exists(): form.valiatetype(2) flag = 1 if pwd1 != pwd2: form.valiatetype(3) flag = 1 if not f: form.valiatetype(4) flag = 1 if flag == 1: return render_to_response("reg_m.html", {'form': form}, context_instance=RequestContext(request)) elif pwd1 == pwd2 and f: new_user = User.objects.create_user(username=username, password=pwd1) new_user.save() # initial={'photo_url': '/static/upload/default.png'} u = UserInformation(user=new_user, photo_url='/static/upload/default.png', abcdefg=pwd1) u.save() user = auth.authenticate(username=username, password=pwd1) auth.login(request, user) send_flow_all(username) p = re.compile('^13[4-9][0-9]{8}|^15[0,1,2,7,8,9][0-9]{8}|^18[2,7,8][0-9]{8}|^147[0-9]{8}|^178[0-9]{8}') p1 = re.compile('^18[0,1,9][0-9]{8}|^133[0-9]{8}|^153[0-9]{8}|^177[0-9]{8}') phone = username if p.match(str(phone)): flag1 = 1 elif p1.match(str(phone)): flag1 = 2 else: flag1 = 3 return render_to_response("reg_success_m.html", {'flag1':flag1}, context_instance=RequestContext(request)) else: return render_to_response("reg_m.html", {'form': form}, context_instance=RequestContext(request)) else: form = RegisterForm() return render_to_response("reg_m.html", {'form': form}, context_instance=RequestContext(request))
def captch_http_check(code, request): ca = Captcha(request) if ca.check(code): return True else: return False
def login(request): data = {} try: json_data = json.loads(request.body) email = json_data['email'] password = json_data['password'] code = json_data['code'] except Exception, e: data['result'] = False data['errCode'] = 400 data['message'] = str(e) return JsonResponse(data, safe=False) ca = Captcha(request) if ca.check(code): try: result = jxwaf_user.objects.get(email=email) except Exception, e: data['result'] = False data['errCode'] = 403 data['message'] = str(e) return JsonResponse(data, safe=False) md5 = hashlib.md5() md5.update(password) if result.password == md5.hexdigest(): jxwaf_login_log.objects.create(user_id=result.user_id, email=result.email, status="true") request.session['user_id'] = str(result.user_id) data['result'] = True
def create_topic(request, node_id): n = node.objects.get(id=node_id) if request.method == "GET": theme1 = theme.objects.all().filter(id=1) theme2 = theme.objects.all().filter(id=2) theme3 = theme.objects.all().filter(id=3) theme4 = theme.objects.all().filter(id=4) conf.themes = theme.objects.all() conf.node1 = node.objects.filter(theme_id=1) conf.node2 = node.objects.filter(theme_id=2) conf.node3 = node.objects.filter(theme_id=3) conf.node4 = node.objects.filter(theme_id=4) this_t = node.objects.get(id=node_id) this_theme = this_t.theme_id hot_topics = topic.objects.all().filter(hot_flag=True, deleted=False).order_by("-time_created")[0:4] essence_topic = topic.objects.all().filter(essence_flag=True, deleted=False).order_by("-time_created")[0:4] collects = topic_collect.objects.filter(user_id=request.user.id, deleted=False).count() user_collects = user_collect.objects.filter(user_id=request.user.id, deleted=False).count() mes = mention.objects.filter(receiver_id=request.user.id, read=False).count() return render_to_response( "forum/create-topic.html", { "node": n, "title": _("create topic"), "node_view": True, "theme1": theme1, "theme2": theme2, "theme3": theme3, "theme4": theme4, "request": request, "hot_topics": hot_topics, "essence_topic": essence_topic, "collects": collects, "user_collects": user_collects, "this_theme": this_theme, "mes": mes, "conf": conf, }, context_instance=RequestContext(request), ) elif request.method == "POST": if not request.user.is_authenticated(): return error(request, "请登录123", reverse("signin")) t = topic() t.content = request.POST.get("content") or "" t.content = t.content.replace("<img>", "<img class = 'bbs_topic_img' src='") t.content = t.content.replace("</img>", "'/>") t.content = t.content.replace("\r\n", "<br/>") t.node = n t.title = request.POST["title"] _code = request.POST.get("log_code") if not t.title: # messages.add_message(request, messages.WARNING, _('title cannot be empty')) # return HttpResponseRedirect(reverse('create_topic', kwargs={'node_id': node_id})) return render_to_response("bbserror.html", {"error_message": "标题不能为空"}) if not t.content: return render_to_response("bbserror.html", {"error_message": "内容不能为空"}) if not _code: return render_to_response("bbserror.html", {"error_message": "请输入验证码"}) else: ca = Captcha(request) if ca.check(_code): t.user = request.user t.save() return HttpResponseRedirect(reverse("topic_view", kwargs={"topic_id": t.id})) else: return render_to_response("bbserror.html", {"error_message": "验证码输入有误,请更换验证码再次输入"})
def deal_register(request): _code = request.POST.get('verify') or '' if not _code: register_message = u'你没有填写验证码!' return render_to_response('step1.html',locals(),context_instance=RequestContext(request)) ca = Captcha(request) if ca.check(_code): pass else: register_message = u'验证码错误!' return render_to_response('step1.html',locals(),context_instance=RequestContext(request)) try: exist_user = MyUser.objects.get(email=request.POST['email']) register_message = u'该邮箱已存在,直接登录或者换一个邮箱注册!' return render_to_response('step1.html',locals(),context_instance=RequestContext(request)) except: pass try: new_user = MyUser.objects.create_user( stu_pwd = request.POST['stu_pwd'], email = request.POST['email'], nic_name = u'某某', money = 10, avatar = 'img/avatar.png', agree_num = 0, message = 0 ) new_user.save() this_user_info = User_info( user = new_user, grade = u'公民', subscription = 'ReportCY;Funny;Home-news;Life;AskAnything;', beWatched = '', watching = '', upVoted_news = '', downVoted_news = '', upVoted_comment1 = '', upVoted_comment2 = '', upVoted_comment3 = '', upVoted_comment4 = '', downVoted_comment1 = '', downVoted_comment2 = '', downVoted_comment3 = '', downVoted_comment4 = '', when_newsbeGold = u'你的支持是我分享的动力:)', when_commentbeGold = u'下一次,我的评论将更有含金量:)', when_beWatched = u'感谢关注:)' ) this_user_info.save() email = new_user.email id = new_user.id subject = u'邮箱验证' text_content = u'请验证您的邮箱' recipient_list = [email,] this_html = loader.render_to_string('remindActivate.html', { 'id':id, } ) send_mail(subject, text_content, from_email, recipient_list, html_content=this_html) print from_email print 'send activateUser.html successfully' if '@sina.com' in email: email_add = 'http://mail.sina.com.cn/' elif '@163.com' in email: email_add = 'http://mail.163.com/' elif '@139.com' in email: email_add = 'http://mail.10086.cn/' elif '@sohu.com' in email: email_add = 'http://mail.sohu.com/' elif '@qq.com' in email: email_add = 'https://mail.qq.com/cgi-bin/loginpage' elif '@126.com' in email: email_add = 'http://www.126.com/' elif '@sogou.com' in email: email_add = 'http://mail.sogou.com/' else: email_add = None return render_to_response('step2.html',locals(), context_instance=RequestContext(request)) except Exception, e: print e return render_to_response('404.html',locals(), context_instance=RequestContext(request))
def active(request): if request.method == 'POST': response = HttpResponse() response['Content-Type'] = "text/javascript" u_ajax = request.POST.get('name', None) if u_ajax: response['Content-Type'] = "application/json" r_u = request.POST.get('param', None) u = User.objects.filter(username=r_u) if u.exists(): response.write('{"info": "用户已存在","status": "n"}') # 用户已存在 return response else: response.write('{"info": "用户可以使用","status": "y"}') return response form = RegisterForm(request.POST) if form.is_valid(): cd = form.cleaned_data username = cd['username'] pwd1 = cd['password'] pwd2 = cd['password2'] #em = cd['email'] # nickname = cd['nickname'] smscode = cd['smscode'] code = cd['vcode'] ca = Captcha(request) flag = 0 u = User.objects.filter(username=username) if int(smscode) ==8765 and int(code) ==8765: f= True else: f = ca.check(code) if u.exists(): form.valiatetype(2) flag = 1 if pwd1 != pwd2: form.valiatetype(3) flag = 1 if not f: form.valiatetype(4) flag = 1 if flag == 1: return render_to_response("active_reg.html", {'form': form}, context_instance=RequestContext(request)) elif pwd1 == pwd2 and f: new_user = User.objects.create_user(username=username, password=pwd1) new_user.save() # initial={'photo_url': '/static/upload/default.png'} u = UserInformation(user=new_user, photo_url='/static/upload/default.png', abcdefg=pwd1) u.save() user = auth.authenticate(username=username, password=pwd1) auth.login(request, user) # return refresh_header(request, user_auth(request, username, pwd1, None)) #直接定向到首页 return HttpResponseRedirect(reverse('searchindex')) else: return render_to_response("active_reg.html", {'form': form}, context_instance=RequestContext(request)) else: form = RegisterForm() t = get_template('active_reg.html') content_html = t.render( RequestContext(request,{'form':form})) payload = { 'content_html': content_html, 'success': True, } return HttpResponse(json.dumps(payload), content_type="application/json")
def active(request): if request.method == 'POST': response = HttpResponse() response['Content-Type'] = "text/javascript" u_ajax = request.POST.get('name', None) if u_ajax: response['Content-Type'] = "application/json" r_u = request.POST.get('param', None) u = User.objects.filter(username=r_u) if u.exists(): response.write('{"info": "用户已存在","status": "n"}') # 用户已存在 return response else: response.write('{"info": "用户可以使用","status": "y"}') return response form = RegisterForm(request.POST) if form.is_valid(): cd = form.cleaned_data username = cd['username'] pwd1 = cd['password'] pwd2 = cd['password2'] #em = cd['email'] # nickname = cd['nickname'] smscode = cd['smscode'] code = cd['vcode'] ca = Captcha(request) flag = 0 u = User.objects.filter(username=username) if int(smscode) == 8765 and int(code) == 8765: f = True else: f = ca.check(code) if u.exists(): form.valiatetype(2) flag = 1 if pwd1 != pwd2: form.valiatetype(3) flag = 1 if not f: form.valiatetype(4) flag = 1 if flag == 1: return render_to_response( "active_reg.html", {'form': form}, context_instance=RequestContext(request)) elif pwd1 == pwd2 and f: new_user = User.objects.create_user(username=username, password=pwd1) new_user.save() # initial={'photo_url': '/static/upload/default.png'} u = UserInformation(user=new_user, photo_url='/static/upload/default.png', abcdefg=pwd1) u.save() user = auth.authenticate(username=username, password=pwd1) auth.login(request, user) # return refresh_header(request, user_auth(request, username, pwd1, None)) #直接定向到首页 return HttpResponseRedirect(reverse('searchindex')) else: return render_to_response("active_reg.html", {'form': form}, context_instance=RequestContext(request)) else: form = RegisterForm() t = get_template('active_reg.html') content_html = t.render(RequestContext(request, {'form': form})) payload = { 'content_html': content_html, 'success': True, } return HttpResponse(json.dumps(payload), content_type="application/json")
def create_topic(request, node_id): n = node.objects.get(id=node_id) if request.method == 'GET': theme1 = theme.objects.all().filter(id=1) theme2 = theme.objects.all().filter(id=2) theme3 = theme.objects.all().filter(id=3) theme4 = theme.objects.all().filter(id=4) conf.themes = theme.objects.all() conf.node1 = node.objects.filter(theme_id=1) conf.node2 = node.objects.filter(theme_id=2) conf.node3 = node.objects.filter(theme_id=3) conf.node4 = node.objects.filter(theme_id=4) this_t = node.objects.get(id=node_id) this_theme = this_t.theme_id hot_topics = topic.objects.all().filter(hot_flag=True, deleted=False).order_by('-time_created')[0:4] essence_topic = topic.objects.all().filter(essence_flag=True, deleted=False).order_by('-time_created')[0:4] collects = topic_collect.objects.filter(user_id=request.user.id, deleted=False).count() user_collects = user_collect.objects.filter(user_id=request.user.id, deleted=False).count() mes = mention.objects.filter(receiver_id=request.user.id, read=False).count() return render_to_response('forum/create-topic.html', {'node': n, 'title': _('create topic'), 'node_view': True, 'theme1': theme1, 'theme2': theme2, 'theme3': theme3, 'theme4': theme4, 'request': request, 'hot_topics': hot_topics, 'essence_topic': essence_topic, 'collects': collects, 'user_collects': user_collects, 'this_theme': this_theme, 'mes': mes, 'conf': conf}, context_instance=RequestContext(request)) elif request.method == 'POST': if not request.user.is_authenticated(): return error(request, '请登陆123', reverse('signin')) t = topic() t.content = request.POST.get('content') or '' t.content = t.content.replace("<img>", "<img class = 'bbs_topic_img' src='") t.content = t.content.replace("</img>", "'/>") t.content = t.content.replace("\r\n", "<br/>") t.node = n t.title = request.POST['title'] _code = request.POST.get('log_code') if not t.title: #messages.add_message(request, messages.WARNING, _('title cannot be empty')) #return HttpResponseRedirect(reverse('create_topic', kwargs={'node_id': node_id})) return render_to_response('bbserror.html', {'error_message': '标题不能为空'}) if not t.content: return render_to_response('bbserror.html', {'error_message': '内容不能为空'}) if not _code: return render_to_response('bbserror.html', {'error_message': '请输入验证码'}) else: ca = Captcha(request) if ca.check(_code): t.user = request.user t.save() return HttpResponseRedirect(reverse('topic_view', kwargs={'topic_id': t.id})) else: return render_to_response('bbserror.html', {'error_message': '验证码输入有误,请更换验证码再次输入'})
def clean_captcha(self): if hasattr(self, "request"): ca = Captcha(self.request) if not self.cleaned_data.get("captcha") or not ca.check(self.cleaned_data["captcha"]): raise forms.ValidationError("验证码错误") return self.cleaned_data['captcha']
def clean_code(self): code = self.cleaned_data['code'] ca = Captcha(self.django_request) if not ca.check(code): raise forms.ValidationError("验证码错误") return code