Пример #1
0
def change_article():
    """
    修改文章
    :return:
    """
    token = request.form['token']
    db = Database()
    user = db.get({'token': token, 'group': 0}, 'user')
    if user:
        article_id = request.form['article_id']
        content = request.form['content']
        title = request.form['title']
        tag = request.form['tag']
        flag = db.new_update({'ID': article_id}, {
            'content': content,
            'title': title,
            'tag': tag,
            'changer': user['ID']
        }, 'article')
        if flag:
            db.insert(
                {
                    'article_id': article_id,
                    'user_id': user['ID'],
                    'type': 1,
                    'content': content
                }, 'history')
            return jsonify({'code': 1, 'msg': 'success'})
        return jsonify({'code': -1, 'msg': 'unknown error'})
    return jsonify({'code': 0, 'msg': 'permission denied'})
Пример #2
0
def add_article():
    """
    添加文章
    :return:
    """
    token = request.form['token']
    db = Database()
    user = db.get({'token': token, 'group': 0}, 'user')
    if user:
        content = request.form['content']
        title = request.form['title']
        tag = request.form['tag']
        flag = db.insert(
            {
                'content': content,
                'title': title,
                'tag': tag,
                'author': user['ID']
            }, 'article')
        if flag:
            article_id = db.sql('select last_insert_id();')
            db.insert(
                {
                    'article_id': article_id[0]['last_insert_id()'],
                    'user_id': user['ID'],
                    'type': 0,
                    'content': content
                }, 'history')
            return jsonify({'code': 1, 'msg': 'success'})
        return jsonify({'code': -1, 'msg': 'unknown error'})
    return jsonify({'code': 0, 'msg': 'permission denied'})
Пример #3
0
def add_article_tag():
    """
    添加文章标签
    :return:
    """
    token = request.form['token']
    db = Database()
    user = db.get({'token': token, 'group': 0}, 'user')
    if user:
        article_id = request.form['article_id']
        name = request.form['name']
        tag_type = request.form['tag_type']
        icon = request.form['icon']
        description = request.form['description']
        flag = db.insert(
            {
                'article_id': article_id,
                'name': name,
                'description': description,
                'icon': icon,
                'tag_type': tag_type
            }, 'article_tag')
        if flag:
            return jsonify({'code': 1, 'msg': 'success'})
        return jsonify({'code': -1, 'msg': 'insert error'})
    return jsonify({'code': 0, 'msg': 'permission denied'})
Пример #4
0
def add_tag():
    """
    添加tag
    :return:
    """
    token = request.form['token']
    db = Database()
    user = db.get({'token': token, 'group': 0}, 'user')
    if user:
        name = request.form['name']
        father = request.form['father']
        if father == '':
            flag = db.insert({'name': name}, 'tag')
            if flag:
                return jsonify({'code': 1, 'msg': 'success'})
            return jsonify({'code': -1, 'msg': 'unknown error'})
        flag = db.insert({'name': name, 'father': father}, 'tag')
        if flag:
            return jsonify({'code': 1, 'msg': 'success'})
        return jsonify({'code': -1, 'msg': 'unknown error'})
    return jsonify({'code': 0, 'msg': 'permission denied'})
Пример #5
0
def add_new_student():
    snum = request.form['snum']
    token = request.form['token']

    db = Database()
    admin = db.get({'token': token, 'group': 0}, 'user')
    if admin:
        exist = db.get({'Snum': snum, 'group': 1}, 'user')
        if exist:
            return jsonify({"code": -2, 'msg': "user exist"})
        result = db.insert({'Snum': snum, 'group': 1}, 'user')
        if result:
            return jsonify({"code": 1, 'msg': "success"})
        return jsonify({"code": 0, 'msg': "error"})
    return jsonify({"code": -1, 'msg': "permission denied"})
Пример #6
0
def add_comment():
    """
    添加评论
    :return:
    """
    token = request.form['token']
    db = Database()
    user = db.get({'token': token}, 'user')
    if user:
        article_id = request.form['article_id']
        content = request.form['content']
        father = request.form['father']
        flag = db.insert(
            {
                'content': content,
                'article_id': article_id,
                'user_id': user['ID'],
                'father': father
            }, 'comment')
        if flag:
            return jsonify({'code': 1, 'msg': 'success'})
        return jsonify({'code': -1, 'msg': 'unknown error'})
    return jsonify({'code': 0, 'msg': 'permission denied'})
Пример #7
0
def add_account():
    """
    添加账户
    :return:
    """
    token = request.form['token']
    db = Database()
    user = db.get({'token': token, 'group': 0}, 'user')
    if user:
        username = request.form['username']
        password = request.form['password']
        s_num = request.form['Snum']
        group = request.form['group']
        flag = db.insert(
            {
                'username': username,
                'password': generate_password(password),
                'Snum': s_num,
                'group': group
            }, 'user')
        if flag:
            return jsonify({'code': 1, 'msg': 'success'})
        return jsonify({'code': -1, 'msg': 'unknown error'})
    return jsonify({'code': 0, 'msg': 'permission denied'})