Esempio n. 1
0
def code(request):
    code = Code(request)
    #code.img_width = 83
    #code.img_height = 30
    #code.font_color = ['black','darkblue','darkred']
    font_size = 30
    return code.display()
Esempio n. 2
0
def login(request):
	if request.method=='POST' and "captcha" not in request.REQUEST:
		username=request.POST['username']
		password=request.POST['password']
		user=authenticate(username=username,password=password)
		if user is not None and user.is_active:
			auth.login(request,user)
			request.session['username']=username
			return HttpResponseRedirect('/accounts/profile/')
		else:
			errors="have error"
			return render_to_response('registration/login.html',{'errors':errors})
	if request.method=='POST' and request.POST['captcha']:
		_code=request.POST.get('captcha')
		code=Code(request)
		if code.check(_code):
			username=request.POST['username']
                	password=request.POST['password']
			user=authenticate(username=username,password=password)
			if user is not None and user.is_active:
                        	auth.login(request,user)
                        	request.session['username']=username
                      	  	return HttpResponseRedirect('/accounts/profile/')
			else:
				errors="have error"
				return render_to_response("registration/login.html",{'errors':errors})
		else:
			capterr="验证码错误!"
			return render_to_response("registration/login.html",{'capterr':capterr,"code":code},context_instance=RequestContext(request))
	return render_to_response('registration/login.html')
Esempio n. 3
0
def index(request):
    _code = request.GET.get('code') or ''
    if not _code:
        return render('index.html', locals())

    code = Code(request)
    if code.check(_code):
        return HttpResponse("""<h1>^_^</h1>""")
    return HttpResponse("""<h1>:-(</h1>""")
Esempio n. 4
0
def index(request):
    _code = request.GET.get('code') or ''
    if not _code:
        return render('index.html',locals())

    code = Code(request)
    if code.check(_code):
        return HttpResponse("""<h1>^_^</h1>""")
    return HttpResponse("""<h1>:-(</h1>""")
Esempio n. 5
0
def verify(request):
    _code = request.REQUEST.get('verify','') 
    code = Code(request)

    # 检查用户输入的验证码是否正确
    if not code.check(_code):
        print 'f**k'
        request.session['next'] = request.path
        return render('verify.html',locals(),context_instance=RequestContext(request))
    else:
        request.session['post_times'] = 0
        request.session['post_stamp'] = time.time()
        return HttpResponseRedirect(request.session.get('next','/'))
Esempio n. 6
0
def verify(request):
    _code = request.REQUEST.get('verify','') 
    code = Code(request)

    # 检查用户输入的验证码是否正确
    if not code.check(_code):
        print 'f**k'
        request.session['next'] = request.path
        return render('verify.html',locals(),context_instance=RequestContext(request))
    else:
        request.session['post_times'] = 0
        request.session['post_stamp'] = time.time()
        return HttpResponseRedirect(request.session.get('next','/'))
Esempio n. 7
0
    def process_request(self,request):
        if request.path == self.verify_code_uri:
            code =  Code(request)
            code.type = 'number'
            return code.display()

        elif request.path == self.verify_page_uri:
            return render('verify.html',locals(),context_instance=RequestContext(request))

        elif request.path == self.verify_check_uri:
            code = Code(request)
            _code = request.REQUEST.get('verify','')

            # 检查用户输入的验证码是否正确
            if not code.check(_code):
                next = self.verify_page_uri
            else:
                request.session['post_times'] = 0
                request.session['post_stamp'] = time.time()
                next = request.session.get('next','/')
            return HttpResponseRedirect(next)
        
        if not request.path in self.expaths:
            timer = time.time() - request.session.get('post_stamp',0)
            post_times = request.session.get('post_times',0)
            # 提交次数是否大于单位时间的最大值
            if request.method == 'POST':
                if post_times >= 4:
                    request.session['next'] = request.META.get('HTTP_REFERER','/')

                    # backup data
                    for k,v in request.POST.items():
                        k = 'backup_{}'.format(k)
                        try:
                            request.session[k] = v
                        except:
                            pass

                    return HttpResponseRedirect(self.verify_page_uri)

                elif timer >= 60:
                    request.session['post_times'] = 0
                    request.session['post_stamp'] = time.time()
                
                request.session['post_times'] = request.session['post_times']+1
                request.session.save()
Esempio n. 8
0
def Login(request):
    ctx = {}
    #广告读取
    Datebase_Advert_Return_1 = IMG.objects.filter(Advert_Num=1)  #广告1
    for Advert_Var_1 in Datebase_Advert_Return_1:
        pass
    Datebase_Advert_Return_2 = IMG.objects.filter(Advert_Num=2)  #广告2
    for Advert_Var_2 in Datebase_Advert_Return_2:
        pass
    ctx['Adverturl1'] = Advert_Var_1.Advert_url
    ctx['Adverturl2'] = Advert_Var_2.Advert_url
    ctx['Advertimg1'] = "/upload/" + str(Advert_Var_1.img)
    ctx['Advertimg2'] = "/upload/" + str(Advert_Var_2.img)
    if request.POST:

        _code = request.POST['InputVerifyCode']

        if _code != '请输入验证码' or request.POST[
                'InputStuNum'] != '请输入十位考生号' or request.POST[
                    'InputName'] != '请输入考生姓名':
            code = Code(request)
            if code.check(_code):
                try:
                    Datebase_Return = Score_Graph.objects.filter(
                        StuNum=request.POST['InputStuNum'],
                        NAME=request.POST['InputName'])
                    for var in Datebase_Return:
                        pass
                    ctx['studentnum'] = var.StuNum
                    ctx['name'] = var.NAME
                    ctx['color'] = var.COLOR
                    ctx['sketch'] = var.SKETCH
                    ctx['linedraw'] = var.LINEDRAW
                    ctx['total'] = var.TOTAL
                    return render(request, "result.html", ctx)
                except:
                    ctx['ErrorMessage'] = '账号或密码输入错误,请检查'
            else:
                ctx['ErrorMessage'] = '验证码输入错误,请重新输入'

        else:
            ctx['ErrorMessage'] = '未输入完整'

    return render(request, "index.html", ctx)
Esempio n. 9
0
def register(request):
    'Register def'
    register = forms.UserForm()
    coder = ''
    if request.method == "POST":
        username = request.POST.get('username')
        password = request.POST.get('password')
        register = models.User.objects.create_user(username=username,password=password)
        register.save()
        register = forms.UserForm(request.POST,request.FILES)
        user = auth.authenticate(username=username,password=password)
        if user is not None:
            profile = models.UserProfile(user=user,img=request.FILES['img'])
            try:
                profile.validate_unique()
                profile.save()
                user = auth.authenticate(username=username,password=password)
                if user is not None and user.is_active:
                    auth.login(request,user)
                return HttpResponseRedirect('/')
            except :
                return HttpResponse('注册失败')
        _code = request.POST.get('code')or ''
        if not _code:
            pass
        code = Code(request)
        if code.check(_code):
            #return HttpResponse(u"ok")
            pass
        else:
            coder = u'验证码错误'
    # menu = models.CateGory.objects.all()
    context = {
            'register':register,
            'coder':coder,
            'menu':MENU,
            }
    context.update(csrf(request))
    return render_to_response('register.html',context)
Esempio n. 10
0
def comment(request):
	post = request.POST
	article_id = post['artical_id']
	name = post['name']
	email = post['email']
	site = post['site']
	content = post['content']
	veri_code = post['veri_code']
	page_url=post['page_url']
	code = Code(request)
	if name == '' or email == '' or content == '':
		return error("姓名、邮箱和内容是必填的。")
	if validateEmailAddr(email) == False:
		return error("你的邮箱地址的格式不对。")
	if veri_code == '':
		return error("请填写验证码")
	if not code.check(veri_code):
		return error("验证码不正确")
	article=Article.objects.get(id = article_id)
	com = Comment(visitor_name=name,visitor_email=email,visitor_site=site,content=content,article = article)
	com.save()
	return HttpResponseRedirect(page_url)
Esempio n. 11
0
def login(request):
    if request.method == 'POST' and "captcha" not in request.REQUEST:
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None and user.is_active:
            auth.login(request, user)
            request.session['username'] = username
            return HttpResponseRedirect('/accounts/profile/')
        else:
            errors = "have error"
            return render_to_response('registration/login.html',
                                      {'errors': errors})
    if request.method == 'POST' and request.POST['captcha']:
        _code = request.POST.get('captcha')
        code = Code(request)
        if code.check(_code):
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None and user.is_active:
                auth.login(request, user)
                request.session['username'] = username
                return HttpResponseRedirect('/accounts/profile/')
            else:
                errors = "have error"
                return render_to_response("registration/login.html",
                                          {'errors': errors})
        else:
            capterr = "验证码错误!"
            return render_to_response("registration/login.html", {
                'capterr': capterr,
                "code": code
            },
                                      context_instance=RequestContext(request))
    return render_to_response('registration/login.html')
Esempio n. 12
0
    def process_request(self, request):
        if request.path == self.verify_code_uri:
            code = Code(request)
            code.type = 'number'
            return code.display()

        elif request.path == self.verify_page_uri:
            return render('verify.html',
                          locals(),
                          context_instance=RequestContext(request))

        elif request.path == self.verify_check_uri:
            code = Code(request)
            _code = request.REQUEST.get('verify', '')
            print 'request', request.REQUEST

            # 检查用户输入的验证码是否正确
            if not code.check(_code):
                next = self.verify_page_uri
            else:
                request.session['post_times'] = 0
                request.session['post_stamp'] = time.time()
                next = request.session.get('next', '/')
            return HttpResponseRedirect(next)

        if not request.path in self.expaths:
            timer = time.time() - request.session.get('post_stamp', 0)
            post_times = request.session.get('post_times', 0)
            # 提交次数是否大于单位时间的最大值
            if request.method == 'POST':
                if post_times >= 3:
                    request.session['next'] = request.META.get(
                        'HTTP_REFERER', '/')
                    return HttpResponseRedirect(self.verify_page_uri)

                elif timer >= 60:
                    request.session['post_times'] = 0
                    request.session['post_stamp'] = time.time()

                request.session[
                    'post_times'] = request.session['post_times'] + 1
                request.session.save()
Esempio n. 13
0
def code(request):
    code =  Code(request)
    code.worlds = ['hello','world','helloworld']
    #code.type = 'world'
    code.type = 'number'
    return code.display()
Esempio n. 14
0
def code(request):
    code = Code(request)
    return code.display()
Esempio n. 15
0
def code(request):
	code=Code(request)
	return code.display()
Esempio n. 16
0
def captcha( request ):
	code = Code(request)
	code.type = 'number'
	code.img_width = 120
	code.img_height = 70
	return code.display()
Esempio n. 17
0
def verify_code(request):
    code =  Code(request)
    code.type = 'number'
    return code.display()
Esempio n. 18
0
def code(request):
    code = Code(request)
    code.worlds = ['hello', 'world', 'helloworld']
    #code.type = 'world'
    code.type = 'number'
    return code.display()
Esempio n. 19
0
def verify_code(request):
    code =  Code(request)
    code.type = 'number'
    return code.display()