Ejemplo n.º 1
0
def wx_register(request):
    if request.method == 'POST':
        response = HttpResponse()
        response['Content-Type'] = "text/javascript"
        openid = request.REQUEST.get('openid', None)
        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 = WXRegisterForm(request.POST)
        if form.is_valid():
            username = request.REQUEST.get('username', None)
            pwd1 = request.REQUEST.get('password', None)
            pwd2 = request.REQUEST.get('password2', None)
            em = request.REQUEST.get('email', None)
            flag = 0
            u = User.objects.filter(username=username)
            if u.exists():
                form.valiatetype(2)
                flag = 1
            if pwd1 != pwd2:
                form.valiatetype(3)
                flag = 1
            if flag == 1:
                return render_to_response("wx_reg.html", {'form': form, 'openid': openid}, context_instance=RequestContext(request))
            elif pwd1 == pwd2:
                new_user = User.objects.create_user(username=username, password=pwd1)
                new_user.save()
                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)
                u = UserInformation.objects.filter(user_id=User.objects.filter(username=username)[0].id)
                tl = ThirdLogin.objects.filter(userInfo_id=u[0].id)
                if tl.exists():
                    tl = ThirdLogin.objects.get(userInfo_id=u[0].id)
                    tl.wxopenId2 = openid
                    tl.save()
                else:
                    tl = ThirdLogin(wxopenId2=openid, wxFlag2=0)
                    tl.userInfo = u[0]
                    tl.wxFlag2 = 1
                    tl.wxBlock = 0
                    tl.save()
                #直接定向到首页
                return HttpResponseRedirect(reverse('searchindex'))
        else:
            return render_to_response("wx_reg.html", {'form': form, 'openid': openid}, context_instance=RequestContext(request))
    else:
        form = WXRegisterForm()
        openid = request.GET.get('openid', None)
        return render_to_response("wx_reg.html", {'form': form, 'openid': openid}, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def wx_binding(request):
    # print "get a request in wx_binding"
    # print "method is :"+request.method
    if request.method == 'POST':
        username = request.REQUEST.get('log_un', None)
        pwd = request.REQUEST.get('log_pwd', None)
        code = request.REQUEST.get('log_code', None)
        openid = request.REQUEST.get('openid', None)
        if username is None:
            form = WXLoginForm(request.POST)
            if form.is_valid():
                cd = form.clean()
                # username = cd['username']
                # pwd = cd['password']
                username = request.REQUEST.get('username', None)
                pwd = request.REQUEST.get('password', None)
                user = auth.authenticate(username=username, password=pwd)

                if user is None:
                    a = 2
                elif not user.is_active:
                    a = 3
                else:
                    auth.login(request, user)
                    a = 1
                if a == 1:
                    a = request.REQUEST.get('next', None)
                    if a:
                        return HttpResponseRedirect(a)
                    else:
                        u = UserInformation.objects.filter(user_id=User.objects.filter(username=username)[0].id)
                        tl = ThirdLogin.objects.filter(userInfo_id=u[0].id)
                        if tl.exists():
                            tl = ThirdLogin.objects.get(userInfo_id=u[0].id)
                            tl.wxopenId2 = openid
                            tl.save()
                        else:
                            tl = ThirdLogin(wxopenId2=openid, wxFlag2=0)
                            tl.userInfo = u[0]
                            tl.wxFlag2 = 1
                            tl.wxBlock = 0
                            tl.save()
                        return HttpResponseRedirect(reverse('searchindex'))
                else:
                    form.valiatetype(a)
                    return render_to_response('wx_login.html', {'form': form, 'openid': openid},
                                              context_instance=RequestContext(request))
            else:
                return render_to_response('wx_login.html', {'form': form, 'openid': openid},
                                          context_instance=RequestContext(request))

        return refresh_header(request, user_auth(request, username, pwd, code))
    else:
        form = WXLoginForm()
        next = request.GET.get('next', None)
        openid = request.GET.get('openid', None)
        return render_to_response('wx_login.html', {'form': form, 'next': next, 'openid': openid},
                                  context_instance=RequestContext(request))
Ejemplo n.º 3
0
def wb_is_first(request):
    resp = 0
    if request.method == 'POST':
        response = HttpResponse()
        response['Content-Type'] = "text/javascript"
        wbid = request.POST.get('wbid', '')
        username = request.POST.get('username', '')
        email = request.POST.get('email', '')
        nickname = request.POST.get('nickname', '')
        url = request.POST.get('url', '')
        if wbid != "" and username == "" and email == "":
            tl = ThirdLogin.objects.filter(wbId=wbid)
            if tl.exists():
                if tl[0].wbFlag == "1":
                    u = User.objects.filter(id=(UserInformation.objects.filter(id=tl[0].userInfo_id)[0].user_id))
                    username = u[0].username
                    password = "******"
                    resp = 1
                else:
                    resp = 0
            else:
                resp = 0
        elif username != "" and email != "":
            u = User.objects.filter(username=username)
            if u.exists():
                resp = 2
            else:
                new_user = User.objects.create_user(username=username, password="******", email=email)
                new_user.save()
                u = UserInformation(user=new_user, photo_url=url)
                u.save()
                tl = ThirdLogin(wbId=wbid, wbFlag=0)
                tl.userInfo = u
                tl.wbFlag = 1
                tl.save()
                resp = 1
        else:
            print " wb something unhopeful happend!"

        if resp == 1:
            user = User.objects.get(username=username)
            user.is_active = True
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth.login(request, user)
            if user is not None and user.is_active:
                auth.login(request, user)
            return HttpResponseRedirect('/')
        else:
            error = ''
            if resp == 2:
                error = "please input correctly!"
            form = TRegForm({'username': nickname, 'wbid': wbid, 'url': url})
            return render_to_response("register.html", {'form': form, 'error': error, 'wbid': wbid}, context_instance=RequestContext(request))
    else:
        print " wb something unhopeful happend2!"
Ejemplo n.º 4
0
def wx_register(request):
    if request.method == 'POST':
        response = HttpResponse()
        response['Content-Type'] = "text/javascript"
        openid = request.REQUEST.get('openid', None)
        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 = WXRegisterForm(request.POST)
        if form.is_valid():
            username = request.REQUEST.get('username', None)
            pwd1 = request.REQUEST.get('password', None)
            pwd2 = request.REQUEST.get('password2', None)
            em = request.REQUEST.get('email', None)
            flag = 0
            u = User.objects.filter(username=username)
            if u.exists():
                form.valiatetype(2)
                flag = 1
            if pwd1 != pwd2:
                form.valiatetype(3)
                flag = 1
            if flag == 1:
                return render_to_response(
                    "wx_reg.html", {
                        'form': form,
                        'openid': openid
                    },
                    context_instance=RequestContext(request))
            elif pwd1 == pwd2:
                new_user = User.objects.create_user(username=username,
                                                    password=pwd1)
                new_user.save()
                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)
                u = UserInformation.objects.filter(user_id=User.objects.filter(
                    username=username)[0].id)
                tl = ThirdLogin.objects.filter(userInfo_id=u[0].id)
                if tl.exists():
                    tl = ThirdLogin.objects.get(userInfo_id=u[0].id)
                    tl.wxopenId2 = openid
                    tl.save()
                else:
                    tl = ThirdLogin(wxopenId2=openid, wxFlag2=0)
                    tl.userInfo = u[0]
                    tl.wxFlag2 = 1
                    tl.wxBlock = 0
                    tl.save()
                #直接定向到首页
                return HttpResponseRedirect(reverse('searchindex'))
        else:
            return render_to_response("wx_reg.html", {
                'form': form,
                'openid': openid
            },
                                      context_instance=RequestContext(request))
    else:
        form = WXRegisterForm()
        openid = request.GET.get('openid', None)
        return render_to_response("wx_reg.html", {
            'form': form,
            'openid': openid
        },
                                  context_instance=RequestContext(request))
Ejemplo n.º 5
0
def wx_binding(request):
    # print "get a request in wx_binding"
    # print "method is :"+request.method
    if request.method == 'POST':
        username = request.REQUEST.get('log_un', None)
        pwd = request.REQUEST.get('log_pwd', None)
        code = request.REQUEST.get('log_code', None)
        openid = request.REQUEST.get('openid', None)
        if username is None:
            form = WXLoginForm(request.POST)
            if form.is_valid():
                cd = form.clean()
                # username = cd['username']
                # pwd = cd['password']
                username = request.REQUEST.get('username', None)
                pwd = request.REQUEST.get('password', None)
                user = auth.authenticate(username=username, password=pwd)

                if user is None:
                    a = 2
                elif not user.is_active:
                    a = 3
                else:
                    auth.login(request, user)
                    a = 1
                if a == 1:
                    a = request.REQUEST.get('next', None)
                    if a:
                        return HttpResponseRedirect(a)
                    else:
                        u = UserInformation.objects.filter(
                            user_id=User.objects.filter(
                                username=username)[0].id)
                        tl = ThirdLogin.objects.filter(userInfo_id=u[0].id)
                        if tl.exists():
                            tl = ThirdLogin.objects.get(userInfo_id=u[0].id)
                            tl.wxopenId2 = openid
                            tl.save()
                        else:
                            tl = ThirdLogin(wxopenId2=openid, wxFlag2=0)
                            tl.userInfo = u[0]
                            tl.wxFlag2 = 1
                            tl.wxBlock = 0
                            tl.save()
                        return HttpResponseRedirect(reverse('searchindex'))
                else:
                    form.valiatetype(a)
                    return render_to_response(
                        'wx_login.html', {
                            'form': form,
                            'openid': openid
                        },
                        context_instance=RequestContext(request))
            else:
                return render_to_response(
                    'wx_login.html', {
                        'form': form,
                        'openid': openid
                    },
                    context_instance=RequestContext(request))

        return refresh_header(request, user_auth(request, username, pwd, code))
    else:
        form = WXLoginForm()
        next = request.GET.get('next', None)
        openid = request.GET.get('openid', None)
        return render_to_response('wx_login.html', {
            'form': form,
            'next': next,
            'openid': openid
        },
                                  context_instance=RequestContext(request))
Ejemplo n.º 6
0
def qq_is_first(request):
    resp = 0
    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
        openid = request.POST.get('openid', '')
        accesstoken = request.POST.get('accessToken', '')
        username = request.POST.get('username', '')
        email = request.POST.get('email', '')
        nickname = request.POST.get('nickname', '')
        url = request.POST.get('url', '')
        if openid != "" and accesstoken != "" and username == "" and email == "":
            tl = ThirdLogin.objects.filter(openId=openid)
            if tl.exists():
                if tl[0].qqFlag == "1":
                    u = User.objects.filter(id=(UserInformation.objects.filter(
                        id=tl[0].userInfo_id)[0].user_id))
                    username = u[0].username
                    resp = 1
                else:
                    resp = 0
            else:
                resp = 0
        elif username != "" and email != "" and openid != "" and accesstoken != "":
            u = User.objects.filter(username=username)
            if u.exists():
                resp = 2
            else:
                new_user = User.objects.create_user(username=username,
                                                    password="******",
                                                    email=email)
                new_user.save()
                u = UserInformation(user=new_user, photo_url=url)
                u.save()
                tl = ThirdLogin(openId=openid,
                                accessToken=accesstoken,
                                qqFlag=0)
                tl.userInfo = u
                tl.qqFlag = 1
                tl.save()
                resp = 1
        else:
            print "qq something unhopeful happend!"

        if resp == 1:
            user = User.objects.get(username=username)
            user.is_active = True
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth.login(request, user)
            if user is not None and user.is_active:
                auth.login(request, user)
            return HttpResponseRedirect('/')
        else:
            error = ''
            if resp == 2:
                error = "please input correctly!"
            form = TRegForm({
                'username': nickname,
                'openid': openid,
                'accessToken': accesstoken,
                'url': url
            })
            return render_to_response("register.html", {
                'form': form,
                'error': error,
                'openid': openid
            },
                                      context_instance=RequestContext(request))
    else:
        print "qq something unhopeful happend2!"
Ejemplo n.º 7
0
def wx_is_first(request):
    resp = 0
    if request.method == 'GET':
        response = HttpResponse()
        response['Content-Type'] = "text/javascript"
        code = request.GET.get("code")
        data = initData(code)
        wxopenid = data['openid']
        wxaccesstoken = data['access_token']
        info = initInfo(wxopenid, wxaccesstoken)
        username = request.POST.get('username', '')
        email = request.POST.get('email', '')
        nickname = info['nickname']
        url = info['headimgurl']
        if wxopenid != "" and wxaccesstoken != "" and username == "" and email == "":
            tl = ThirdLogin.objects.filter(wxopenId=wxopenid)
            if tl.exists():
                if tl[0].wxFlag == "1":
                    u = User.objects.filter(id=(UserInformation.objects.filter(
                        id=tl[0].userInfo_id)[0].user_id))
                    username = u[0].username
                    resp = 1
                else:
                    resp = 0
            else:
                resp = 0
        else:
            print "wx something unhopeful happend!"

        if resp == 1:
            user = User.objects.get(username=username)
            user.is_active = True
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth.login(request, user)
            if user is not None and user.is_active:
                auth.login(request, user)
            return HttpResponseRedirect('/')
        else:
            error = ''
            if resp == 2:
                error = "please input correctly!"
            form = TRegForm({
                'username': nickname,
                'openid': wxopenid,
                'accessToken': wxaccesstoken,
                'url': url
            })
            return render_to_response("register.html", {
                'form': form,
                'error': error,
                'wxopenid': wxopenid
            },
                                      context_instance=RequestContext(request))
    elif request.method == 'POST':
        response = HttpResponse()
        response['Content-Type'] = "text/javascript"
        wxopenid = request.POST.get('openid', '')
        wxaccesstoken = request.POST.get('accessToken', '')
        username = request.POST.get('username', '')
        email = request.POST.get('email', '')
        nickname = request.POST.get('nickname', '')
        url = request.POST.get('url', '')
        if username != "" and email != "" and wxopenid != "" and wxaccesstoken != "":
            u = User.objects.filter(username=username)
            if u.exists():
                resp = 2
            else:
                new_user = User.objects.create_user(username=username,
                                                    password="******",
                                                    email=email)
                new_user.save()
                u = UserInformation(user=new_user, photo_url=url)
                u.save()
                tl = ThirdLogin(wxopenId=wxopenid,
                                wxaccessToken=wxaccesstoken,
                                wxFlag=0)
                tl.userInfo = u
                tl.wxFlag = 1
                tl.save()
                resp = 1
        else:
            print "wx something unhopeful happend!"

        if resp == 1:
            user = User.objects.get(username=username)
            user.is_active = True
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth.login(request, user)
            if user is not None and user.is_active:
                auth.login(request, user)
            return HttpResponseRedirect('/')
        else:
            error = ''
            if resp == 2:
                error = "please input correctly!"
            form = TRegForm({
                'username': nickname,
                'openid': wxopenid,
                'accessToken': wxaccesstoken,
                'url': url
            })
            return render_to_response("register.html", {
                'form': form,
                'error': error,
                'wxopenid': wxopenid
            },
                                      context_instance=RequestContext(request))

    else:
        print "wx something unhopeful happend2!"
Ejemplo n.º 8
0
def qq_is_first(request):
    resp = 0
    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
        openid = request.POST.get('openid', '')
        accesstoken = request.POST.get('accessToken', '')
        username = request.POST.get('username', '')
        email = request.POST.get('email', '')
        nickname = request.POST.get('nickname', '')
        url = request.POST.get('url', '')
        if openid != "" and accesstoken != "" and username == "" and email == "":
            tl = ThirdLogin.objects.filter(openId=openid)
            if tl.exists():
                if tl[0].qqFlag == "1":
                    u = User.objects.filter(id=(UserInformation.objects.filter(id=tl[0].userInfo_id)[0].user_id))
                    username = u[0].username
                    resp = 1
                else:
                    resp = 0
            else:
                resp = 0
        elif username != "" and email != "" and openid != "" and accesstoken != "":
            u = User.objects.filter(username=username)
            if u.exists():
                resp = 2
            else:
                new_user = User.objects.create_user(username=username, password="******", email=email)
                new_user.save()
                u = UserInformation(user=new_user, photo_url=url)
                u.save()
                tl = ThirdLogin(openId=openid, accessToken=accesstoken, qqFlag=0)
                tl.userInfo = u
                tl.qqFlag = 1
                tl.save()
                resp = 1
        else:
            print "qq something unhopeful happend!"

        if resp == 1:
            user = User.objects.get(username=username)
            user.is_active = True
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth.login(request, user)
            if user is not None and user.is_active:
                auth.login(request, user)
            return HttpResponseRedirect('/')
        else:
            error = ''
            if resp == 2:
                error = "please input correctly!"
            form = TRegForm({'username': nickname, 'openid': openid, 'accessToken': accesstoken, 'url': url})
            return render_to_response("register.html", {'form': form, 'error': error, 'openid': openid}, context_instance=RequestContext(request))
    else:
        print "qq something unhopeful happend2!"