本文整理汇总了Python中DjangoCaptcha.Captcha.validate方法的典型用法代码示例。如果您正苦于以下问题:Python Captcha.validate方法的具体用法?Python Captcha.validate怎么用?Python Captcha.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DjangoCaptcha.Captcha
的用法示例。
在下文中一共展示了Captcha.validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: signin
# 需要导入模块: from DjangoCaptcha import Captcha [as 别名]
# 或者: from DjangoCaptcha.Captcha import validate [as 别名]
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)
示例2: signup
# 需要导入模块: from DjangoCaptcha import Captcha [as 别名]
# 或者: from DjangoCaptcha.Captcha import validate [as 别名]
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)
示例3: admin_login
# 需要导入模块: from DjangoCaptcha import Captcha [as 别名]
# 或者: from DjangoCaptcha.Captcha import validate [as 别名]
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)
示例4: index
# 需要导入模块: from DjangoCaptcha import Captcha [as 别名]
# 或者: from DjangoCaptcha.Captcha import validate [as 别名]
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>""")