Exemple #1
0
def auth_del():
    try:
        auth_id = int(request.form.get("id"))
        auth = Auth.query.get_or_404(auth_id)
        db.session.delete(auth)
        db.session.commit()
    except Exception as e:
        print(e)
        ResultEnum.FAIL.value.msg = "服务器异常,删除失败!"
        return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
    ResultEnum.SUCCESS.value.msg = "删除成功"
    return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))
Exemple #2
0
def admin_user_del():
    try:
        id = int(request.form.get("id"))
        admin_user = AdminUser.query.get_or_404(id)
        db.session.delete(admin_user)
        db.session.commit()
    except Exception as e:
        print(e)
        ResultEnum.FAIL.value.msg = "服务器异常,删除失败!"
        return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
    ResultEnum.SUCCESS.value.msg = "删除成功"
    return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))
Exemple #3
0
def user_del():
    try:
        user_id = int(request.form.get("user_id"))
        # user = User.query.get_or_404(user_id)
        user = User.query.filter_by(id=user_id).first_or_404()
        db.session.delete(user)
        db.session.commit()
    except Exception as e:
        print(e)
        ResultEnum.FAIL.value.msg = "服务器异常,删除失败!"
        return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
    ResultEnum.SUCCESS.value.msg = "删除成功"
    return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))
Exemple #4
0
def preview_del():
    try:
        preview_id = int(request.form.get("id"))
        preview = Preview.query.filter_by(id=preview_id).first_or_404()

        # 将对应的预告封面(logo)文件删除
        del_file(app.config["UP_DIR"] + "/" + preview.logo)
        # 数据库相应记录删除
        db.session.delete(preview)
        db.session.commit()
    except Exception as e:
        print(e)
        ResultEnum.FAIL.value.msg = "服务器异常,删除失败"
        return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
    ResultEnum.SUCCESS.value.msg = "删除成功"
    return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))
Exemple #5
0
def video_del():
    try:
        video_id = int(request.form.get("id"))
        video = Video.query.filter_by(id=video_id).first_or_404()
        db.session.delete(video)
        db.session.commit()
        # TODO 实际上还需要删除视频相关的评论和相应的文件(视频源和封面图片)
        up_dir_path = app.config["UP_DIR"]
        del_file(up_dir_path + "/" + video.url)
        del_file(up_dir_path + "/" + video.logo)
    except Exception as e:
        print(e)
        ResultEnum.FAIL.value.msg = "服务器异常,删除失败"
        return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
    ResultEnum.SUCCESS.value.msg = "删除成功"
    return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))
Exemple #6
0
def role_del():
    try:
        role_id = int(request.form.get("id"))

        # 如果有管理员绑定了该角色则不允许删除该角色
        if AdminUser.query.filter_by(role_id=role_id).count() > 0:
            ResultEnum.FAIL.value.msg = "删除该角色请先解绑相关管理员!"
            return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))

        role = Role.query.get_or_404(role_id)
        db.session.delete(role)
        db.session.commit()
    except Exception as e:
        print(e)
        ResultEnum.FAIL.value.msg = "服务器异常,删除失败!"
        return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
    ResultEnum.SUCCESS.value.msg = "删除成功"
    return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))
Exemple #7
0
def tag_del():
    try:
        tag_id = int(request.form.get("id"))
        # 判断标签之下是否有视频,有的话不允许删除
        if Video.query.filter_by(tag_id=tag_id).count() > 0:
            ResultEnum.FAIL.value.msg = "删除该标签请先解绑相关视频!"
            return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
        tag = Tag.query.filter_by(id=tag_id).first_or_404()
        tag_name = tag.name
        db.session.delete(tag)
        db.session.commit()
        record_admin_op_log("删除标签 " + tag_name)
    except Exception as e:
        print(e)
        ResultEnum.FAIL.value.msg = "服务器异常,删除失败"
        return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
    ResultEnum.SUCCESS.value.msg = "删除成功"
    return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))
Exemple #8
0
def modify_pwd():
    try:
        newpwd = request.form.get("newpwd")
        # 获取当前管理员用户
        admin_user = AdminUser.query.filter_by(
            id=session["admin_user_id"]).first()
        # 更新密码
        from werkzeug.security import generate_password_hash
        admin_user.pwd = generate_password_hash(newpwd)
        db.session.add(admin_user)
        db.session.commit()

        # 修改密码日志记录
        record_admin_op_log("修改密码")
    except Exception as e:
        print(e)
        ResultEnum.FAIL.value.msg = "服务器异常,修改失败"
        return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
    ResultEnum.SUCCESS.value.msg = "修改成功"
    return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))
Exemple #9
0
def collection_add():
    try:
        vid = int(request.form.get("vid"))
        user_id = session["user_id"]

        # 查询是否收藏过了
        cnt = Collection.query.filter(Collection.video_id == vid,
                                      Collection.user_id == user_id).count()
        if cnt >= 1:
            ResultEnum.SUCCESS.value.msg = "已收藏!"
            return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))

        # 收藏(数据库落地)
        new_col = Collection(video_id=vid, user_id=user_id)
        db.session.add(new_col)
        db.session.commit()
    except Exception as e:
        print(e)
        ResultEnum.FAIL.value.msg = "服务器异常,收藏失败!"
        return jsonify(ResultEnum.obj2json(ResultEnum.FAIL.value))
    ResultEnum.SUCCESS.value.msg = "收藏成功"
    return jsonify(ResultEnum.obj2json(ResultEnum.SUCCESS.value))