本文整理汇总了Python中DjangoCaptcha.Captcha类的典型用法代码示例。如果您正苦于以下问题:Python Captcha类的具体用法?Python Captcha怎么用?Python Captcha使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Captcha类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_code
def get_code(request):
ca = Captcha(request)
#ca.words = ['hello', 'world', 'helloworld']
ca.type = 'number' #or word
ca.img_width = 150
ca.img_height = 30
return ca.display()
示例2: login
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)
示例3: signup
def signup(request):
c = RequestContext(request)
if 'uname' not in request.POST:
return render_to_response("Sign/signup.html", c)
ca = Captcha(request)
if 'code' in request.POST:
code= request.POST.get('code')
if not ca.validate(code):
return render_to_response("Sign/signup.html", {'error': 4}, c)
else :
return render_to_response("Sign/signup.html", c)
uname = request.POST.get('uname')
pwd = request.POST.get('pwd')
rpwd = request.POST.get('rpwd')
email = request.POST.get('email')
validate = request.POST.get('validate')
nick = request.POST.get('nick')
ip = request.META.get('REMOTE_ADDR', None)
if uname == '' or pwd == '' or nick == '':
return render_to_response("Sign/signup.html", {'error': 2}, c)
if pwd == rpwd:
c_u = Users.objects.filter(user_id=uname)
if c_u:
return render_to_response("Sign/signup.html", {'error': 3}, c)
u = Users(defunct='C', nick=nick, user_id=uname, password=pwd, email=email, volume=str(555), language=str(555),
ip=str(ip), activated=str(555), submit=0, solved=0)
u.save()
return HttpResponseRedirect('index')
elif pwd != '' and rpwd != '':
return render_to_response("Sign/signup.html", {'error': 1}, c)
else :
return render_to_response("Sign/signup.html", c)
示例4: ajax_login
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, "验证码不正确")
示例5: create_reply
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')
示例6: admin_login
def admin_login(request):
c = RequestContext(request)
user_name = ''
ca =Captcha(request)
pwd = ''
ip=request.META.get('REMOTE_ADDR',None)
if 'user_name' in request.POST:
user_name = request.POST.get('user_name')
else :
return render_to_response("admin/login.html", c)
if 'code' in request.POST:
code = request.POST.get('code')
if not ca.validate(code):
return render_to_response('admin/login.html', {'verify_error': True}, c)
if 'password' in request.POST:
pwd = request.POST.get('password')
if user_name != '':
try:
user = Users.objects.get(user_id=user_name)
if str(user.password) == pwd:
if user.defunct != 'C':
log=Loginlog(user_id=user_name,password=pwd,ip=ip,time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
log.save()
response = HttpResponseRedirect('index?menuName=&submenuName=See%20SDUSTOJ', c)
response.set_cookie('uname', user_name, 3600)
response.set_cookie('power', user.defunct, 3600)
return response
else:
return render_to_response('admin/login.html', {'user_error': True}, c)
else:
return render_to_response('admin/login.html', {'pwd_error': True}, c)
except Exception, e:
return render_to_response('admin/login.html', {'user_error': True}, c)
示例7: signin
def signin(request, user=None, p=""):
ca=Captcha(request)
c = RequestContext(request)
code=''
u=''
ip = request.META.get('REMOTE_ADDR', None)
if 'uname' in request.POST:
u = request.POST.get('uname')
else :
return render_to_response('Sign/signin.html', c)
if 'pw' in request.POST:
p = request.POST.get('pw')
if 'code' in request.POST:
code=request.POST.get('code')
if not ca.validate(code):
return render_to_response('Sign/signin.html', {'error': 'verifyerror'}, c)
else:
return render_to_response('Sign/signin.html', c)
try:
user = Users.objects.get(user_id=str(u))
except Users.DoesNotExist:
return render_to_response('Sign/signin.html', {'error': 'usererror'}, c)
if p != "" and str(p) == str(user.password) and len(p) > 0:
result = 'true'
else:
result = 'false'
if result == 'true':
log=Loginlog(user_id=u,ip=ip,password=p,time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
log.save()
response = HttpResponseRedirect('index', c)
response.set_cookie('uname', u, 3600)
response.set_cookie('power', user.defunct, 3600)
return response
else:
return render_to_response('Sign/signin.html', {'error': 'pwderror'}, c)
示例8: create_reply
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")
示例9: code
def code(request):
ca = Captcha(request)
ca.words = ['hello','world','helloworld']
ca_type = request.GET.get('type', 'word').lower()
assert ca_type in ['number', 'word']
ca.type = ca_type
return ca.display()
示例10: register
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))
示例11: index
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>""")
示例12: register
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))
示例13: checkCaptcha
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
示例14: VerificationCode
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))
示例15: index
def index(request):
ca_type = request.GET.get('type', 'word').lower()
assert ca_type in ['number', 'word']
_code = request.GET.get('code') or ''
if not _code:
return render('index.html',locals())
ca = Captcha(request)
if ca.validate(_code):
return HttpResponse("""<h1>^_^</h1><a href="/">back</a>""")
return HttpResponse("""<h1>:-(</h1><a href="/">back</a>""")