Exemplo n.º 1
0
def userAPI(request):
    # 判断用户是否登陆,同时判断用户登录的是否是管理员账号
    try:
        isLogin = isLoginTrue(request)
        if isLogin == 0 or isLogin == -1:
            redirectTitle = "请登录之后再进行操作"
            redirectUrl = "/login"
            return render(request, "currency/loginAndRegister/handle.html",
                          locals())
    except Exception as e:
        redirectTitle = "超出权限,请登录管理员账号后再执行操作"
        redirectUrl = "/login"
        return render(request, "currency/loginAndRegister/handle.html",
                      locals())
        # 判断是否管理登陆完成,如果是,则执行以下代码,否则已经在上述代码中跳转到指定页面。

    # 获取信息,记录log
    information = Information()
    pageInformation = information.getAll()
    webLogger(request.META)
    nav = 'api'
    pagetitle = "API中心"
    userData = currency.models.UserModel.objects.get(uid=isLogin[2])
    secretid = userData.username
    secretkey = md5(
        (str(md5(str(userData.password).encode("utf-8"))) +
         "=!liuyublog-liuyublog!=" +
         str(md5(str(userData.username).encode("utf-8")))).encode("utf-8"))
    return render(
        request, "usercenter/%s/%s" %
        (information.getValue("templatesUserCenterName"), "api.html"),
        locals())
Exemplo n.º 2
0
def albumContent(request):

    try:
        # 获取信息,记录log
        information = Information()
        pageInformation = information.getAll()
        webLogger(request.META)
        try:
            userIP = request.META["HTTP_X_FORWARDED_FOR"]
        except:
            userIP = request.META["REMOTE_ADDR"]

        loginId = isLoginTrue(request)
        try:
            isloginData = True
            userId = loginId[2]

        except Exception as e:
            errorLogger(e)
            isloginData = False

        if ipCounter(userIP, information.getValue("maxCounter")):
            category = currency.models.CategoryModel.objects.filter(type="3")

            aid = request.GET.get("aid")
            if aid:
                categoryData = category.get(cid=aid)
                pictureData = album.models.ImagesModel.objects.filter(
                    album=categoryData, is_recommend=True).order_by("-iid")
            else:
                pictureData = list(
                    album.models.ImagesModel.objects.filter(
                        is_recommend=True).order_by("-iid"))
                random.shuffle(pictureData)
                pictureData = pictureData[0:20]
            return render(
                request, "album/%s/%s" %
                (information.getValue("templatesAlbumName"), "index.html"),
                locals())
        else:
            return redirect("/sorry")
    except Exception as e:
        errorLogger(e)
        request.session["errorNumber"] = "100004"
        return redirect("/wrong")
Exemplo n.º 3
0
def userIndex(request):
    # 判断用户是否登陆,同时判断用户登录的是否是管理员账号
    try:
        isLogin = isLoginTrue(request)
        if isLogin == 0 or isLogin == -1:
            redirectTitle = "请登录之后再进行操作"
            redirectUrl = "/login"
            return render(request, "currency/loginAndRegister/handle.html",
                          locals())
    except Exception as e:
        redirectTitle = "超出权限,请登录管理员账号后再执行操作"
        redirectUrl = "/login"
        return render(request, "currency/loginAndRegister/handle.html",
                      locals())
        # 判断是否管理登陆完成,如果是,则执行以下代码,否则已经在上述代码中跳转到指定页面。

    # 获取信息,记录log
    information = Information()
    pageInformation = information.getAll()
    webLogger(request.META)
    nav = 'index'
    pagetitle = "仪表盘"
    userData = currency.models.UserModel.objects.get(uid=isLogin[2])
    articleData = currency.models.ArticleModel.objects.all().order_by("-aid")
    comments = currency.models.CommentsModel.objects.all()
    tempComments = []
    for eve in comments.filter(username=userData.username, usertype=1):
        tempComments.append((eve, comments.filter(pid=eve.cid)))
    if comments.filter(username=userData.username, usertype=1).count() > 6:
        articleData = articleData[
            0:comments.filter(username=userData.username, usertype=1).count()]
    else:
        articleData = articleData[0:6]

    return render(
        request, "usercenter/%s/%s" %
        (information.getValue("templatesUserCenterName"), "index.html"),
        locals())
Exemplo n.º 4
0
def blogArticle(request):
    try:
        # 获取信息,记录log
        information = Information()
        pageInformation = information.getAll()
        webLogger(request.META)
        try:
            userIP = request.META["HTTP_X_FORWARDED_FOR"]
        except:
            userIP = request.META["REMOTE_ADDR"]
        if ipCounter(userIP, information.getValue("maxCounter")):

            # 头部名人名言
            sentenceData = Sentence()
            (sentence, author) = sentenceData.getOneSentence()
            sentence = sentence[0:-1]

            tagsData = currency.models.TagsModel.objects.filter(
                type=1).order_by("?")[0:20]
            categoryList = currency.models.CategoryModel.objects.filter(type=1)

            aidData = request.GET.get("aid")

            articleData = currency.models.ArticleModel.objects.get(aid=aidData)
            if not articleData.is_recommend:
                clickCount = int(articleData.click_count) + 1
                currency.models.ArticleModel.objects.filter(
                    aid=aidData).update(click_count=clickCount)

                articleListTemp = currency.models.ArticleModel.objects.filter(
                    is_recommend=False)
                articleList = articleListTemp.order_by("-aid")
                totalCount = articleList.count()
                # recommend = RecommendedHandle(numCount=5)
                # otherArticle = []
                # for eveArticle in articleList:
                #     if str(aidData) == str(eveArticle.aid):
                #         articleData = eveArticle
                #     else:
                #         otherArticle.append((eveArticle.aid,"%s,%s,%s"%(eveArticle.title,eveArticle.category.name,eveArticle.desc)))

                # recommendList = recommend.getArticleList("%s,%s,%s"%(articleData.title,articleData.category.name,articleData.desc),otherArticle)
                # recommendArticle = []
                # for eveArticle in recommendList:
                #     tempArticle = currency.models.ArticleModel.objects.get(aid=eveArticle)
                #     recommendArticle.append((tempArticle,getDeafulatPic(tempArticle.content).replace("blog","backblog")))

                recommendArticleData = articleListTemp.order_by(
                    "-click_count")[0:3]
                recommendArticle = []
                for eveHotData in recommendArticleData:
                    picUrl = getDeafulatPic(eveHotData.content)
                    recommendArticle.append(
                        (eveHotData, picUrl.replace("blog", "backblog")))

                loginId = isLoginTrue(request)
                totalUser = usercenter.models.UserModel.objects.all()
                try:
                    isLogin = True
                    userId = loginId[2]
                    userData = totalUser.get(uid=userId)
                except Exception as e:
                    errorLogger(e)
                    isLogin = False

                if request.method == "POST":
                    username = request.POST.get("name")
                    email = request.POST.get("email")
                    comment = request.POST.get("comment")

                    comment = filterTags(comment)
                    spamData = SpamHandle(comment).getSpam()
                    '''
                    cid = models.AutoField(primary_key=True)
                    content = models.TextField(verbose_name="评论内容")
                    date_publish = models.DateTimeField(auto_now_add=True, verbose_name="发布时间")
                    username = models.CharField(max_length=50, verbose_name="用户")
                    usertype = models.IntegerField(default=0, verbose_name="用户类型")
                    qq = models.CharField(max_length=13, blank=True, null=True, verbose_name="QQ号")
                    mobile = models.CharField(max_length=11, blank=True, null=True, unique=True, verbose_name="电话号")
                    pid = models.ForeignKey('self', blank=True, null=True, verbose_name="父级评论")
                    is_recommend = models.BooleanField(default=True, verbose_name="是否显示")
                    watched = models.BooleanField(default=True, verbose_name="是否查看")
                    email = models.CharField(max_length=50, verbose_name="邮箱")
                    article = models.CharField(max_length=50, verbose_name="文章")
                    '''

                    if spamData:
                        try:
                            username = userData.username
                            email = userData.email
                            typeData = 1
                        except:
                            typeData = 0

                        # 登录用户的typeData是1,否则是0

                        currency.models.CommentsModel.objects.create(
                            username=username,
                            email=email,
                            content=comment,
                            is_recommend=False,
                            watched=False,
                            article_title=articleData.title,
                            article=articleData,
                            usertype=typeData,
                        )
                        stateData = "留言成功,我会尽快审核,给您反馈!感谢您的支持哦!"
                    else:
                        stateData = "系统判断,您的信息可能是垃圾信息,维护网络信息整洁是我们每个公民的义务!请您重新发送!"

                commenData = currency.models.CommentsModel.objects.filter(
                    article=aidData, is_recommend=False).order_by("-cid")
                comm = []
                tempHave = []
                for eveComment in commenData:
                    if eveComment.pid:
                        if eveComment.pid.is_recommend:
                            if eveComment.pid.cid not in tempHave:
                                if eveComment.usertype == 1:
                                    comm.append(
                                        (eveComment,
                                         totalUser.get(username=eveComment.
                                                       username).photo))
                                else:
                                    comm.append(
                                        (eveComment, "/files/userFace/1.jpg"))
                                tempHave.append(eveComment.pid.cid)
                    else:
                        if eveComment.cid not in tempHave:
                            if eveComment.usertype == 1:
                                comm.append(
                                    (eveComment,
                                     totalUser.get(
                                         username=eveComment.username).photo))
                            else:
                                comm.append(
                                    (eveComment, "/files/userFace/1.jpg"))

                return render(
                    request,
                    "blog/%s/%s" % (information.getValue("templatesBlogName"),
                                    "content.html"), locals())
            else:
                request.session["errorNumber"] = "100009"
                return redirect("/wrong")
        else:
            return redirect("/sorry")
    except Exception as e:
        errorLogger(e)
        request.session["errorNumber"] = "100004"
        return redirect("/wrong")
Exemplo n.º 5
0
def userInfor(request):

    # 判断用户是否登陆,同时判断用户登录的是否是管理员账号
    try:
        isLogin = isLoginTrue(request)
        if isLogin == 0 or isLogin == -1:
            redirectTitle = "请登录之后再进行操作"
            redirectUrl = "/login"
            return render(request, "currency/loginAndRegister/handle.html",
                          locals())
    except Exception as e:
        redirectTitle = "超出权限,请登录管理员账号后再执行操作"
        redirectUrl = "/login"
        return render(request, "currency/loginAndRegister/handle.html",
                      locals())
        # 判断是否管理登陆完成,如果是,则执行以下代码,否则已经在上述代码中跳转到指定页面。

    if request.method == "POST":
        '''
        email	[email protected]
        password	liuyuliuyu
        phone	13500993691
        photo	/files/userFace/39.jpg
        qq	
        sex	男
        username	liuyu
        wechat	None
        '''
        try:
            userData = currency.models.UserModel.objects.get(uid=isLogin[2])
            email = request.POST.get("email", userData.email)
            password = request.POST.get("password", userData.password)
            phone = request.POST.get("phone", userData.phone)
            photo = request.POST.get("photo", userData.photo)
            qq = request.POST.get("qq", userData.qq)
            sex = request.POST.get("sex", userData.sex)
            wechat = request.POST.get("wechat", userData.wechat)

            currency.models.UserModel.objects.filter(uid=isLogin[2]).update(
                photo=photo,
                phone=phone,
                qq=qq,
                sex=sex,
                wechat=wechat,
                email=email,
                password=password)
            status = "修改成功"
        except:
            status = "修改失败"

    userData = currency.models.UserModel.objects.get(uid=isLogin[2])

    # 获取信息,记录log
    information = Information()
    pageInformation = information.getAll()
    webLogger(request.META)
    nav = 'setting'

    pagetitle = "个人信息"

    photoFile = []
    for evePhoto in range(1, 41):
        photoFile.append((evePhoto, "/files/userFace/%d.jpg" % (evePhoto)))

    return render(
        request, "usercenter/%s/%s" %
        (information.getValue("templatesUserCenterName"), "infor.html"),
        locals())