Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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, "验证码不正确")
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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')
Exemplo n.º 7
0
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")
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
def validateCode(request):
    _code = request.POST.get('code') or ''
    ca = Captcha(request)
    if ca.check(_code):
        return True
    else:
        return False
Exemplo n.º 12
0
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()
Exemplo n.º 13
0
def check(request):
    _code = request.POST.get('code')

    ca = Captcha(request)
    if ca.check(_code):
        return True
    else:
        return False
Exemplo n.º 14
0
def code(request):
    ca = Captcha(request)
    ca.words = ['google', 'twitter', 'facebook', 'tomcat', 'nginx']
    ca_mode = request.GET.get('mode', 'word').lower()
    assert ca_mode in ['number', 'word', 'four_number']

    ca.mode = ca_mode
    return ca.display()
Exemplo n.º 15
0
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))
Exemplo n.º 16
0
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>""")
Exemplo n.º 17
0
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))
Exemplo n.º 18
0
def code(request):
    nums = [2, 3, 4, 5, 6, 7, 8, 9]

    ca = Captcha(request)
    ca.words = [
        ''.join([str(random.sample(nums, 1)[0]) for i in xrange(0, 4)])
    ]
    ca.type = 'word'

    return ca.display()
Exemplo n.º 19
0
def code(request):
    def gene_text():
        source = 'ABCDEFGHKMNPRSTUVWXYZabcdefghkmnpqrstuvwxyz23456789'
        return ''.join(random.sample(list(source), 4))

    ca = Captcha(request)
    ca.words = [gene_text()]
    ca.type = "word"

    return ca.display()
Exemplo n.º 20
0
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))
Exemplo n.º 22
0
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')
Exemplo n.º 23
0
def index(request):
    ca_mode = request.GET.get('mode', 'word').lower()
    assert ca_mode in ['number', 'word', 'four_number']

    _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>""")
Exemplo n.º 24
0
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>""")
Exemplo n.º 25
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
Exemplo n.º 26
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
Exemplo n.º 27
0
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)
Exemplo n.º 28
0
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)
Exemplo n.º 29
0
def login(request):
    title = '单点登录'
    user = request.user
    passwd_url = settings.PASSWD_URL
    show_captcha = settings.SHOW_CAPTCHA
    back = request.GET.get('back')
    if not back: back = '/'
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        code = request.POST.get('code')
        if show_captcha:
            if not Captcha(request).check(code):
                result = '验证码错误'
                return render_to_response('main/login.html', locals())
        user = auth.authenticate(username=username, password=password)
        if user is not None:
            auth.login(request, user)
            token_confirm = Token(settings.SECRET_KEY)
            token_key = '%s' % username
            token = token_confirm.generate_validate_token(token_key)
            #redirect_uri = '%s?token=%s' % (back, token)
            #return HttpResponseRedirect(redirect_uri)
            response = HttpResponseRedirect(back)
            response.set_cookie('sso_token',
                                token,
                                settings.COOKIE_EXPIRES,
                                domain=settings.SESSION_COOKIE_DOMAIN)
            return response
        else:
            result = '用户名或密码错误'
    return render_to_response('main/login.html', locals())
Exemplo n.º 30
0
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
Exemplo n.º 31
0
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)
Exemplo n.º 32
0
def verifycode(request):
    figures = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    ca = Captcha(request)
    ca.words = [''.join([str(random.sample(figures, 1)[0]) for i in range(0, 4)])]
    ca.type = 'word'
    ca.img_width = 60
    ca.img_height = 20
    return ca.display()
Exemplo n.º 33
0
def code(request):
    figures = [1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
    ca = Captcha(request)
    ca.words = [''.join([str(random.sample(figures,1)[0]) for i in range(0,5)])]
    ca.type = 'word'
    ca.img_width = 150
    ca.img_height = 35
    return ca.display()
Exemplo n.º 34
0
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)
Exemplo n.º 35
0
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)
Exemplo n.º 36
0
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))
Exemplo n.º 37
0
def user_auth(request, username, password):
    user = auth.authenticate(username=username, password=password)
    ca = Captcha(request)
    if user is None:
        a = 2
    elif not user.is_active:
        a = 3
    else:
        auth.login(request, user)
        a = 1
    return a
Exemplo n.º 38
0
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))
Exemplo n.º 39
0
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)
Exemplo n.º 40
0
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)
Exemplo n.º 41
0
def code(request):
    ca = Captcha(request)
    figures = [2, 3, 4, 5, 6, 7, 8, 9]
    ca.words = [
        ''.join(str(random.sample(figures, 1)[0]) for i in range(0, 4))
    ]
    ca.type = 'word'
    ca.img_height = 30
    ca.img_width = 100
    return ca.display()
Exemplo n.º 42
0
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)
Exemplo n.º 43
0
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)
Exemplo n.º 44
0
def verifycode(request):
    figures = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    ca = Captcha(request)
    ca.words = [''.join([str(random.sample(figures, 1)[0]) for i in range(0, 4)])]
    ca.type = 'word'
    ca.img_width = 60
    ca.img_height = 20
    return ca.display()
Exemplo n.º 45
0
def code(request):
    ca=Captcha(request)
    figures = [2,3,4,5,6,7,8,9]
    ca.words = [''.join(str(random.sample(figures,1)[0]) for i in range(0,4))]
    ca.type= 'word'
    ca.img_height = 30
    ca.img_width = 100
    return ca.display()
Exemplo n.º 46
0
 def get(self, request):
     from DjangoCaptcha import Captcha
     import random
     l = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
     s = random.sample(l, 4)
     ca = Captcha(request)
     ca.words = [''.join(s)]
     ca.img_width = 120
     ca.img_height = 30
     ca.type = 'word'
     self.is_weixin()
     return ca.display()
Exemplo n.º 47
0
def captcha(request):
    figures = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    #figures = [chr(i) for i in range(97,123)]
    ca = Captcha(request)
    ca.words = [
        ''.join([str(random.sample(figures, 1)[0]) for i in range(0, 4)])
    ]
    #ca.type = 'number' #数学运算
    ca.type = 'word'  #字符串
    ca.img_width = 80
    ca.img_height = 20
    return ca.display()
def getVerificationCode(request):
    ca = Captcha(request)
    figures = [2, 3, 4, 5, 6, 7, 8, 9]
    ca.img_width = 103
    ca.img_height = 30
    ca.words = [''.join([str(random.sample(figures, 1)[0]) for i in range(0, 4)])]
    ca.type = 'word'
    # print ca.words
    return ca.display()
Exemplo n.º 49
0
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)
Exemplo n.º 50
0
    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)
Exemplo n.º 51
0
    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})
Exemplo n.º 52
0

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)
Exemplo n.º 53
0
def code(request):
    ca = Captcha(request)
    ca.words = ['hello', 'world', 'apple', 'orange', 'banana', 'xiaobei', 'beibei']
    ca.type =  'number'
    return ca.display()
Exemplo n.º 54
0
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))
Exemplo n.º 55
0
def captcha_view(request):
    ca = Captcha(request)
    ca.img_width = 100
    ca.type = 'word'
    return ca.display()
Exemplo n.º 56
0
def captch_http_check(code, request):
    ca = Captcha(request)
    if ca.check(code):
        return True
    else:
        return False
Exemplo n.º 57
0
def captcha(request):
    ca = Captcha(request)
    ca.mode = 'four_number'
    ca.img_width = 100
    ca.img_height = 30
    return ca.display()