示例#1
0
def loginHandle(request):
    username = request.POST.get("username")
    pwd = request.POST.get("pwd")
    email = request.POST.get("email")
    print(username, pwd, email)
    # return HttpResponse(utils.returnResult(0, "登录成功"))
    # userinfo=inadmin.objects.get(username=username)
    # print( userinfo.username)
    try:
        userinfo = inadmin.objects.get(username=username)
    except:
        userinfo = None
    print(userinfo)
    if userinfo:
        print("用户名存在")
        if pwd == userinfo.password:
            response = HttpResponse(utils.returnResult(0, "登录成功"))
            response.set_cookie("uid",
                                userinfo.username,
                                max_age=60 * 60 * 24 * 3)
            return response
        return HttpResponse(utils.returnResult(1, "密码失败"))
    else:
        print("用户名不存")
        return HttpResponse(utils.returnResult(1, "用户名不存"))
示例#2
0
def getarticleDiteinfo(request):
    id = 1
    sql = "SELECT * FROM articlecontent WHERE aid= %s"
    data = id
    db.Db.cursor.execute(sql, data)
    userinfo = db.Db.cursor.fetchone()
    print(userinfo)
    return HttpResponse(utils.returnResult(0, "", userinfo))
示例#3
0
def btnclickaddHandle(request):
    uid = request.GET.get("uid")
    uid1 = request.GET.get("uid1")
    print(eval(uid))
    for i in eval(uid):
        print(i)
    news.objects.filter(id__in=eval(uid)).update(num=uid1)
    return HttpResponse(utils.returnResult(0, "发布成功"))
示例#4
0
def addrecommendlistHandle(request):
    print(122)
    id = request.GET.get("uid")
    print(id)
    list = serializers.serialize("json",
                                 inposition_content.objects.filter(id=id))
    print(list)
    return HttpResponse(utils.returnResult(0, "1111", list))
示例#5
0
def getArticleList(request):
    uid = request.GET.get("uid")
    print(uid)
    sql = "SELECT id,title,uid FROM article WHERE uid=%s"
    data = uid
    db.Db.cursor.execute(sql, data)
    userinfo = db.Db.cursor.fetchall()
    print(userinfo)
    return HttpResponse(utils.returnResult(0, "", userinfo))
示例#6
0
def getusername(request):
    '''uid换取数据'''
    uid = request.GET.get("uid")
    print(uid)
    sql = "SELECT username  FROM user WHERE id= %s "
    data = uid
    db.Db.cursor.execute(sql, data)
    userinfo = db.Db.cursor.fetchone()
    print(userinfo)
    return HttpResponse(utils.returnResult(0, "", userinfo))
示例#7
0
def loginHangle(request):
    username = request.POST.get("username")
    pwd = request.POST.get("pwd")
    print(username,pwd)
    sql="SELECT id,password FROM user WHERE username= %s"
    data=username
    db.Db.cursor.execute(sql, data)
    userinfo = db.Db.cursor.fetchone()
    print( userinfo)
    if userinfo:
        print("用户名存在")
        if pwd==userinfo["password"]:
            response=HttpResponse(utils.returnResult(0, "登录成功",{"uid":userinfo["id"]}))
            response.set_cookie("uid",userinfo["id"],max_age=60*60*24*3)
            return response
        return HttpResponse(utils.returnResult(1, "密码失败"))
    else:
        print("用户名不存")
        return HttpResponse(utils.returnResult(1, "用户名不存"))
示例#8
0
def menuHandle(request):
    menutitle = request.POST.get("menutitle")
    menuaddnum = request.POST.get("menuadd")
    radionum = request.POST.get("radionum")
    print(menutitle, radionum)
    newscontent = inmenu(menuname=menutitle,
                         mecatid=radionum,
                         menuadd=menuaddnum)
    newscontent.save()
    return HttpResponse(utils.returnResult(0, "发布成功"))
示例#9
0
def recommendHandle(request):
    menutitle = request.POST.get("menutitle")
    recomtitle = request.POST.get("recomtitle")
    radionum = request.POST.get("radionum")
    print(menutitle, recomtitle, radionum)
    timenum = datetime.now()
    inposition = inposition_content(content=menutitle,
                                    newsid=radionum,
                                    createttime=timenum)
    inposition.save()
    return HttpResponse(utils.returnResult(0, "发布成功"))
示例#10
0
def registHangle(request):
    username = request.POST.get("username")
    pwd = request.POST.get("pwd")
    email = request.POST.get("email")
    print(username,pwd,email)
    now=datetime.now()
    print(now)
    sql="SELECT * FROM user WHERE username=%s"
    data=(username)

    # db.Db.cursor.execute(sql, data)
    # userinfo=db.Db.cursor.fetchone()
    # print(userinfo)
    userinfo=db.Db.select(sql,0,data)
    if userinfo=="error":
        return HttpResponse(utils.returnResult(1, "用户名已存在"))
    else:
        return HttpResponse(utils.returnResult(1, "用户名已存在"))
    if(userinfo):
        print("用户存在")
        return HttpResponse(utils.returnResult(1, "用户名已存在"))

    keyvalue="username,password,registtime"
    value="%s,%s,%s"
    data = (username, pwd,datetime.now())
    print(data)
    if(email):
        print("邮箱存在")
        keyvalue+=",email"
        value+=",%s"
        data = (username, pwd, datetime.now(), email)
    sql="INSERT INTO user("+keyvalue+") values("+value+")"
    print(sql)

    try:
        db.Db.cursor.execute(sql, data)
        db.Db.conn.commit()
        return HttpResponse(utils.returnResult(0, "注册成功"))
    except Exception as e:
        return HttpResponse(utils.returnResult(1, "注册失败"))
示例#11
0
def addArticleHangle(request):
    '''添加处理页面'''
    title = request.POST.get("title")
    uid = request.POST.get("uid")
    content = request.POST.get("content")
    print(title, uid, content)
    sql = "INSERT INTO article(title,uid) VALUES (%s,%s)"
    data = (title, uid)
    db.Db.cursor.execute(sql, data)
    insertid = db.Db.conn.insert_id()
    print(insertid)
    sql = "INSERT INTO articlecontent(aid,content) VALUES (%s,%s)"
    data = (insertid, content)
    db.Db.cursor.execute(sql, data)
    db.Db.conn.commit()
    return HttpResponse(utils.returnResult(0, "发布成功"))
示例#12
0
def contentHandle(request):
    title = request.POST.get("title")
    colorlist = request.POST.get("colorlist")
    num = request.POST.get("num")
    content = request.POST.get("content")
    headImg = request.FILES.get("headImg")
    content1 = request.POST.get("content1")
    print(content1)
    print(title, colorlist, num, headImg, content)
    size = getsize(headImg.size)
    if size > 100:
        print("文件过大")
    type = headImg.name.split(".")[-1]
    print(type)
    if type not in ["jpg", "png", "jpeg", "gif", "bmp"]:
        print("类型错误")
    timestamp = int(datetime.now().timestamp() * 1000000)
    print(timestamp)
    timenum = datetime.now()
    newsname = "head" + str(timestamp) + "." + type
    print(newsname)
    imgpath = "static/uploads/" + newsname
    with open(imgpath, 'wb') as f:
        for file in headImg.chunks():
            f.write(file)
            f.flush()

    newscontent = innews_content(newsid=1, content=content, newstime=timenum)
    newscontent.save()
    # list=innews_content.objects.all().values("id")
    list = innews_content.objects.filter(content=content).order_by('-id')
    for item in list:
        cat = item.id

    newarticle = news(title=title,
                      title_font_colour=colorlist,
                      thumb=newsname,
                      num=num,
                      catid=cat)
    newarticle.save()

    return HttpResponse(utils.returnResult(0, "发布成功"))
示例#13
0
def adminHandle(request):
    username = request.POST.get("username")
    pwd = request.POST.get("pwd")
    email = request.POST.get("email")
    content1 = request.POST.get("content1")
    content = request.POST.get("content")
    newtime = datetime.now()
    headImg = request.FILES.get("headImg")
    size = getsize(headImg.size)
    if size > 100:
        print("文件过大")
    type = headImg.name.split(".")[-1]
    print(type)
    if type not in ["jpg", "png", "jpeg", "gif", "bmp"]:
        print("类型错误")
    timestamp = int(datetime.now().timestamp() * 1000000)
    print(timestamp)
    timenum = datetime.now()
    newsname = "head" + str(timestamp) + "." + type
    print(newsname)
    imgpath = "static/uploads/" + newsname
    with open(imgpath, 'wb') as f:
        for file in headImg.chunks():
            f.write(file)
            f.flush()

    print(username, pwd, email, content1, content)

    user = inadmin(username=username,
                   password=pwd,
                   email=email,
                   content=content,
                   registtime=newtime,
                   images=newsname)
    user.save()
    return HttpResponse(utils.returnResult(0, "注册成功"))
示例#14
0
def delHandle(request):
    uid = request.GET.get("uid")
    print(uid)
    response = response = HttpResponse(utils.returnResult(0, "ok"))
    response.delete_cookie('uid')
    return response
示例#15
0
def indexHandle(request):
    list = serializers.serialize("json", inmenu.objects.filter(mecatid=1))
    print(list)
    return HttpResponse(utils.returnResult(1, "用户名不存", list))
示例#16
0
def deladminHandle(request):
    id = request.GET.get("uid")
    print(id)
    inadmin.objects.filter(id=id).delete()

    return HttpResponse(utils.returnResult(0, "删除成功"))
示例#17
0
def delrecommendHandle(request):
    id = request.GET.get("uid")
    print(id)
    inposition_content.objects.filter(id=id).delete()

    return HttpResponse(utils.returnResult(0, "删除成功"))
示例#18
0
def delcontentHandle(request):
    id = request.GET.get("uid")
    print(id)
    news.objects.filter(id=id).delete()
    innews_content.objects.filter(newsid=id).delete()
    return HttpResponse(utils.returnResult(0, "删除成功"))