Ejemplo n.º 1
0
def article():
    if request.method == 'POST':
        # 文章类别
        classes = request.form['classes']
        where = "where classes='" + classes + "'"
        count = sql.select(mydb, 'article', where, 'count(1)')
        artNew = sql.select(mydb, 'article',
                            where + ' ORDER By time desc limit 6')
        datas = (count[0], artNew)
        return jsonify(datas)
    else:
        return 'false'
Ejemplo n.º 2
0
def login(us=user):
    if request.method == 'POST':
        if not request.form['sno']:
            raise Exception('sno', 'Invalid sno')
        if not request.form['pwd']:
            raise Exception('pwd', 'Invalid pwd')
        # return jsonify(request.form['sno'],request.form['pwd'])
        uid = next_id()
        pwd = request.form['pwd']
        sno = request.form['sno']
        # 查找是否已注册
        where = "where sno=" + sno
        res = sql.select(mydb, 'user', where)
        if len(res) > 0:
            return 'hasLogin'  #已注册
        sha1_pwd = '%s:%s' % (uid, pwd)
        # 摘要算法防篡改
        sha1 = hashlib.sha1()
        sha1.update(sha1_pwd.encode('utf-8'))
        sha1_pwd = sha1.hexdigest()
        user = us.User(uid, sno, sha1_pwd)
        if user.save(mydb, sql) == 1:
            return 'loginSuccess'  #注册成功
        else:
            return 'loginFails'
Ejemplo n.º 3
0
def perios(status):
    if request.method == 'POST':
        if status == 'init':
            return jsonify(
                sql.select(mydb, 'journal', 'where 1', 'id,qikan,qikanshu'))
        elif status == 'selectAll':
            qikan = request.form['qikan']
            qikanshu = request.form['qikanshu']
            where = "where qikan='" + qikan + "' and " + "qikanshu='" + qikanshu + "'"
            return jsonify(sql.select(mydb, 'journal', where, 'id,title'))
        elif status == 'selectPost':
            id = request.form['id']
            where = 'where id=' + id
            return jsonify(
                sql.select(mydb, 'journal', where,
                           'title,author,keyword,digest'))
Ejemplo n.º 4
0
def select():
    classes = request.form['classes']
    pages = request.form['pages']
    pages = (int(pages) - 1) * 6
    where = "where classes='" + classes + "'"
    artNew = sql.select(
        mydb, 'article',
        where + ' ORDER By time desc limit ' + str(pages) + ',6')
    return jsonify(artNew)
Ejemplo n.º 5
0
def cms():
    if request.method == 'POST':
        zhanghao = request.get_json()['zhanghao']
        pwd = request.get_json()['pwd']
        where = "where zhanghao='" + zhanghao + "' and pwd='" + pwd + "'"
        res = sql.select(mydb, 'cms', where)
        if len(res) == 1:
            return 'success'
        else:
            return 'fails'
Ejemplo n.º 6
0
def articleShow(status):
    if request.method == 'POST':
        data = request.get_json()
        if status == 'init':
            return jsonify(sql.select(mydb, 'article', 'where 1'))
        elif status == 'delete':
            where = 'id=' + str(data['id'])
            res = sql.delete(mydb, 'article', where)
            if res == 1:
                return 'deletSuccess'
Ejemplo n.º 7
0
def home():
    if request.method == 'POST':
        v1 = sql.select(mydb, 'article', "where classes='长院要闻'", "count(1)")
        v2 = sql.select(mydb, 'article', "where classes='综合新闻'", "count(1)")
        v3 = sql.select(mydb, 'article', "where isReport='true'", "count(1)")
        v4 = sql.select(mydb, 'article', "where classes='公告通知'", "count(1)")
        artHot = sql.select(mydb, 'article', "ORDER BY likes desc limit 6",
                            "id,title,likes")
        artNew = sql.select(
            mydb, 'article',
            "where isReport='false' ORDER By time desc limit 6",
            "id,title,subhead,imgUrl,time")
        #传到前端数据
        datas = (v1[0], v2[0], v3[0], v4[0], artHot, artNew)
        return jsonify(datas)
Ejemplo n.º 8
0
def landing():
    if request.method == 'POST':
        sno = request.form['sno']
        pwd = request.form['pwd']
        #是否注册
        where = "where sno=" + sno
        res = sql.select(mydb, 'user', where)
        if len(res) <= 0:
            return 'noLogin'  #未注册
        uid = res[0]['uid']
        user_pwd = res[0]['pwd']  #数据库中的sha摘要
        sha1 = hashlib.sha1()
        sha1.update(uid.encode('utf-8'))
        sha1.update(b':')
        sha1.update(pwd.encode('utf-8'))
        sha1_pwd = sha1.hexdigest()
        # sha1_pwd   根据登录时传过来的账号、密码,重新计算的sha摘要
        if sha1_pwd != user_pwd:
            return 'landingFails'
        else:
            return jsonify(('landingSuccess', uid))
Ejemplo n.º 9
0
def userCenter():
    if request.method == 'POST':
        uid = request.form['uid']
        where = "where uid='" + uid + "' and collect=1"
        return jsonify(sql.select(mydb, 'user_likes', where, 'postId,title'))
Ejemplo n.º 10
0
def hasaudit():
    if request.method == 'POST':
        where = "where hasAudit=true"
        res = sql.select(mydb, 'delivery', where)
        return jsonify(res)
Ejemplo n.º 11
0
def page(status):
    if request.method == 'POST':
        id = request.form['id']
        uid = request.form['uid']
        title = request.form['title']
        # 获取文章详细内容
        if status == 'init':
            where = 'where id=' + str(id)
            return jsonify(sql.select(mydb, 'article', where))
        # 点赞
        elif status == 'likes':
            where = 'where postId=' + str(id) + " and uid='" + str(uid) + "'"
            res = sql.select(mydb, 'user_likes', where)
            if len(res) == 0:
                res = sql.insert(mydb,
                                 'user_likes',
                                 uid=uid,
                                 postId=id,
                                 likes=1,
                                 title=title)
                # 插入成功
                if res[0] == 1:
                    mycursor = mydb.cursor(dictionary=True)
                    sqls = "update article set likes=likes+1 where id=" + str(
                        id)
                    mycursor.execute(sqls)
                    mycursor.close()
                    mydb.commit()
                    return 'success'
                else:
                    return 'fails'
            elif len(res) == 1:
                mycursor = mydb.cursor(dictionary=True)
                sqls = "update user_likes set likes=1 where postId=" + str(id)
                mycursor.execute(sqls)
                mycursor.close()
                mydb.commit()
                if mycursor.rowcount == 1:
                    mycursor = mydb.cursor(dictionary=True)
                    sqls = "update article set likes=likes+1 where id=" + str(
                        id)
                    mycursor.execute(sqls)
                    mycursor.close()
                    mydb.commit()
                    return 'success'
                else:
                    return 'fails'
        # 收藏
        elif status == 'collect':
            where = 'where postId=' + str(id) + " and uid='" + str(uid) + "'"
            res = sql.select(mydb, 'user_likes', where)
            if len(res) == 0:
                res = sql.insert(mydb,
                                 'user_likes',
                                 uid=uid,
                                 postId=id,
                                 collect=1,
                                 title=title)
                # 插入成功
                if res[0] == 1:
                    return 'success'
                else:
                    return 'fails'
            elif len(res) == 1:
                mycursor = mydb.cursor(dictionary=True)
                sqls = "update user_likes set collect=1 where postId=" + str(
                    id)
                mycursor.execute(sqls)
                mycursor.close()
                mydb.commit()
                if mycursor.rowcount == 1:
                    return 'success'
                else:
                    return 'fails'
Ejemplo n.º 12
0
def topAritcle():
    if request.method == 'POST':
        return jsonify(
            sql.select(mydb, 'article', "ORDER BY likes desc limit 6",
                       "id,title,likes"))