本文整理汇总了Python中captcha.models.CaptchaStore.generate_key方法的典型用法代码示例。如果您正苦于以下问题:Python CaptchaStore.generate_key方法的具体用法?Python CaptchaStore.generate_key怎么用?Python CaptchaStore.generate_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类captcha.models.CaptchaStore
的用法示例。
在下文中一共展示了CaptchaStore.generate_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vote
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def vote(request, question_id):
response_json = {}
if request.method == 'POST':
form = RadioVoteForm(request.POST)
if form.is_valid():
p = get_object_or_404(Question, pk=question_id)
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
response_json['error'] = "You didn't select a choice."
else:
selected_choice.votes += 1
selected_choice.save()
response_json['status'] = 1
response_json['new_cptch_key'] = CaptchaStore.generate_key()
response_json['new_cptch_image'] = captcha_image_url(response_json['new_cptch_key'])
else:
response_json['status'] = 0
response_json['form_errors'] = form.errors
response_json['new_cptch_key'] = CaptchaStore.generate_key()
response_json['new_cptch_image'] = captcha_image_url(response_json['new_cptch_key'])
print >>sys.stderr, 'VOTE FORM ERROR: ' + str(form.errors)
else:
response_json['error'] = "Method is not POST"
return HttpResponse(json.dumps(response_json), content_type="application/json")
示例2: setUp
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def setUp(self):
CaptchaStore.generate_key()
self.hashkey = CaptchaStore.objects.all()[0].hashkey
self.response = CaptchaStore.objects.all()[0].response
self.user = User.objects.create_user(username='user_exist',
email='[email protected]',
password='glass_onion')
示例3: login
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def login(request):
#刷新验证码
if request.GET.get('newsn')=='1':
csn=CaptchaStore.generate_key()
cimageurl= captcha_image_url(csn)
return HttpResponse(cimageurl)
t = loader.get_template('backstage/login.html')
c = RequestContext(request, {'foo': 'bar'})
if request.POST:
form = CaptchaTestForm(request.POST)
# Validate the form: the captcha field will automatically
# check the input
if form.is_valid():
human = True
to_json_response = dict()
to_json_response['status'] = 0
to_json_response['form_errors'] = form.errors
to_json_response['new_cptch_key'] = CaptchaStore.generate_key()
to_json_response['new_cptch_image'] = captcha_image_url(to_json_response['new_cptch_key'])
return HttpResponse(json.dumps(to_json_response), content_type='application/json')
else:
form = CaptchaTestForm()
#return HttpResponse(t.render(c))
#return render_to_response('backend/login.html',locals())
return render_to_response('backstage/login.html',
locals(),
context_instance=RequestContext(request, processors=[]))
示例4: refresh_captcha
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def refresh_captcha(request):
"""
刷新验证码图片
"""
new_key = CaptchaStore.generate_key()
new_img = captcha_image_url(new_key)
return HttpResponse(new_img)
示例5: login_page
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def login_page(request):
"""
Display the login form.
"""
flag =request.GET.get('flag',0)
csrf_token = csrf(request)['csrf_token']
if (settings.FEATURES['AUTH_USE_CERTIFICATES'] and
ssl_get_cert_from_request(request)):
# SSL login doesn't require a login view, so redirect
# to course now that the user is authenticated via
# the decorator.
return redirect('/course')
form = CaptchaLoginForm()
if request.is_ajax():
new_cptch_key = CaptchaStore.generate_key()
cpt_image_url = captcha_image_url(new_cptch_key)
return JsonResponse({'captcha_image_url': cpt_image_url})
return render_to_response(
'login.html',
{
'flag':flag,
'csrf': csrf_token,
'forgot_password_link': "//{base}/login#forgot-password-modal".format(base=settings.LMS_BASE),
'platform_name': microsite.get_value('platform_name', settings.PLATFORM_NAME),
'form': form
}
)
示例6: forgot
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def forgot(request):
# 用于刷新验证码
hashkey = CaptchaStore.generate_key()
image_url = captcha_image_url(hashkey)
if request.method == 'POST':
form = ForgotForm(request.POST)
if form.is_valid():
email = request.POST.get("email")
try:
user = User.objects.get(email=email)
except:
user = None
form.errors['email'] = '此邮箱未注册'
if user:
resetBiz = ResetPwdBiz()
resetBiz.send_email(email)
return render_to_response("forget.html",
{"success": form},
context_instance = RequestContext(request)
)
return render_to_response("forget.html",
{"hashkey": hashkey, "image_url": image_url, "form": form},
context_instance = RequestContext(request)
)
return render_to_response("forget.html",
{"hashkey": hashkey, "image_url": image_url, "form": form},
context_instance = RequestContext(request)
)
return render_to_response("forget.html",
{"hashkey": hashkey, "image_url": image_url},
context_instance = RequestContext(request)
)
示例7: bbs_pub
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def bbs_pub(request):
categories = Category.objects.all()
hashkey = CaptchaStore.generate_key()
image_url = captcha_image_url(hashkey)
if request.method == 'POST':
form = BbsPubForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
bbsBiz = BbsBiz()
bbs_category = bbsBiz.getCategory(cd['bbs_category'])
bbs_author = bbsBiz.getBbsAuthorByReq(request.user)
if bbs_category and bbs_author:
bbs_content = remove_tags(cd['bbs_content'], "html body script")
BBS.objects.create(
bbs_title = cd['bbs_title'],
bbs_content = bbs_content,
view_count = 0,
bbs_category = bbs_category,
bbs_author = bbs_author,
)
return HttpResponseRedirect(reverse('home'))
return render_to_response("bbs_pub.html", {"form": form,
"categories": categories,
"hashkey": hashkey, "image_url": image_url},
context_instance = RequestContext(request))
form = BbsPubForm()
return render_to_response("bbs_pub.html",
{"form": form, "categories": categories,
"hashkey": hashkey, "image_url": image_url},
context_instance = RequestContext(request))
示例8: mailbox
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def mailbox(request,template_name="oa/site/email.html",domain="domain"):
site = get_site(request)
if not site:
return render(request, "404.html")
school = site.school
if request.GET.get('newsn')=='1':
csn=CaptchaStore.generate_key()
cimageurl= captcha_image_url(csn)
parent_domain = helpers.get_parent_domain(request)
return HttpResponse(parent_domain + cimageurl)
if request.method == 'POST':
form = MailBoxForm(request.POST)
print form.errors,'eeeeeeeeeeeeeeeeeee'
if request.is_ajax():
return helpers.ajax_validate_form(form)
if form.is_valid():
human = True
mail = form.save(commit=False)
# mail.user = school.header
mail.site = site
mail.save()
if mail.id:
messages.success(request, u'已成功发送%s ' % mail.title)
return redirect(request.get_full_path())
else:
form = MailBoxForm()
ctx = {'form':form,'class':'startes','site':site}
return render(request, template_name, ctx)
示例9: form_valid
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def form_valid(self, form):
#form.save()
if self.request.is_ajax():
to_json_response = dict()
to_json_response['new_cptch_key'] = CaptchaStore.generate_key()
to_json_response['new_cptch_image'] = captcha_image_url(to_json_response['new_cptch_key'])
#[验证用户名密码](http://www.cnblogs.com/linjiqin/p/3638501.html)
username = self.request.POST['username']
password = self.request.POST['password']
if username=="" or username.isspace():
to_json_response['status'] = 0
to_json_response['data'] = "用户名不能为空"
if password=="" or password.isspace():
to_json_response['status'] = 0
to_json_response['data'] = "密码不能为空"
user = auth.authenticate(username=username, password=password)
if user is not None:
if user.is_active:
auth.login(self.request, user)
to_json_response['status'] = 1
to_json_response['data'] = "OK"
else:
to_json_response['status'] = 0
to_json_response['data'] = "["+username+"]已被暂时禁用"
else:
to_json_response['status'] = 0
to_json_response['data'] = "用户名或密码不正确,请重试"
return HttpResponse(json.dumps(to_json_response), content_type='application/json')
示例10: new_captcha
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def new_captcha(request):
if request.is_ajax():
print('This is a ajax')
csn=CaptchaStore.generate_key()
imageurl = captcha_image_url(csn)
data = {"imageurl": imageurl, "csn": csn}
return JsonResponse(data)
示例11: resend_activation_link
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def resend_activation_link(request):
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
if request.method == 'POST' and request.is_ajax():
captcha_key = CaptchaStore.generate_key()
captcha_image = captcha_image_url(captcha_key)
form = ResendActivationEmailForm(request.POST)
if form.is_valid():
email = form.cleaned_data["email"]
users = get_user_model().objects.filter(email=email, is_active=False)
if not users.count():
form._errors["email"] = (_("Account for email address is not registered or already activated."),)
else:
for user in users:
for profile in RegistrationProfile.objects.filter(user=user):
if profile.activation_key_expired():
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
profile.activation_key = hashlib.sha1(salt + user.username).hexdigest()
profile.save()
user.date_joined = timezone.now()
user.save()
profile.send_activation_email(site)
# messages.add_message(request, messages.INFO, _('Resend activation link done'))
return ajaxResponse(False, response_header=_('Resend activation link done'), captcha_key=captcha_key,
captcha_image=captcha_image)
return ajaxResponse(True, form=form, captcha_key=captcha_key, captcha_image=captcha_image)
form = ResendActivationEmailForm()
return render(request, "registration/resend_activation_email_form.html", {"form": form})
示例12: post
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
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})
示例13: forgot_passwd
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def forgot_passwd(request):
if request.method == "POST":
if not request.is_ajax():
raise Http404
result={}
passwd = request.POST.get('passwd', '')
telcode = request.POST.get("code", '')
mobile = request.POST.get('mobile', '')
if not (passwd and telcode and mobile):
result['code'] = '3'
result['res_msg'] = u'传入参数不足!'
return JsonResponse(result)
ret = verifymobilecode(mobile,telcode)
if ret != 0:
result['code'] = 1
if ret == -1:
result['res_msg'] = u'请先获取手机验证码'
elif ret == 1:
result['res_msg'] = u'手机验证码输入错误!'
elif ret == 2:
result['res_msg'] = u'手机验证码已过期,请重新获取'
else:
user = MyUser.objects.get(mobile=mobile)
user.set_password(passwd)
user.save(update_fields=["password"])
result['code'] = 0
return JsonResponse(result)
else:
hashkey = CaptchaStore.generate_key()
codimg_url = captcha_image_url(hashkey)
return render(request,'registration/forgot_passwd.html',
{'hashkey':hashkey, 'codimg_url':codimg_url})
示例14: get
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def get(self, request, sub=None, *args, **kwargs):
if request.GET.get('newsn') == '1':
csn = CaptchaStore.generate_key()
cimageurl = captcha_image_url(csn)
return HttpResponse(cimageurl)
if sub == 'wrong':
raise Http404
if sub == 'stall':
if not request.user.is_authenticated():
return redirect("dashboard:register", sub='signupin')
seller = request.user.seller_set.filter(pmo=self.pmo)
if seller.count() != 1:
return redirect("dashboard:register", sub='signupin')
seller = seller[0]
if 'item_id' in request.GET:
item_id = request.GET['item_id']
item = Item.objects.filter(pk=item_id, pmo=self.pmo, seller=seller)
if item.count() == 1:
return render(
request,
'dashboard/register/stall/itemform.html',
{
'item': item[0],
'images': self._get_images(item[0])
}
)
else:
return HttpResponse("")
if 'page' in request.GET:
try:
page = int(request.GET['page'])
except ValueError:
raise Http404
items, page = self._get_items(seller, page)
return render(request, 'dashboard/register/stall/itemtable.html', {
'items': items,
'page': page
})
is_stall = sub == 'stall'
if seller.is_stall == is_stall:
sub = 'stall'
items, page = self._get_items(seller)
kwargs.update({
'seller': seller,
'items': items,
'page': page,
})
else:
kwargs.update({
'is_stall': is_stall,
'correct_url': reverse('dashboard:register', kwargs={'sub': 'consign' if is_stall else 'stall'})
})
sub = 'wrong'
elif sub == 'signupin':
kwargs.update({
'login_form': LoginForm(),
'error_message_login': self._err_dict.get(request.GET.get('validated', None), "")
})
return super().get(request, sub, *args, **kwargs)
示例15: reload_captcha
# 需要导入模块: from captcha.models import CaptchaStore [as 别名]
# 或者: from captcha.models.CaptchaStore import generate_key [as 别名]
def reload_captcha(request):
form = CaptchaForm()
print "==================check======================"
to_json_response = dict()
to_json_response['status'] = 1
to_json_response['new_cptch_key'] = CaptchaStore.generate_key()
to_json_response['new_cptch_image'] = captcha_image_url(to_json_response['new_cptch_key'])
return HttpResponse(json.dumps(to_json_response), content_type='application/json')