Esempio n. 1
0
def checkOK():
    videoID = request.args.get("id")
    video = db.session.query(Video).filter_by(id=videoID).first()
    video.state = "审核通过"
    new_message = Message(account=video.account,
                          fromAccount="official",
                          description="你的视频(标题:" + video.title + ")已审核通过",
                          time=datetime.datetime.now(),
                          username="******",
                          userAvatarUrl="static/avatars/officialavatar.jpg")
    db.session.add(new_message)
    db.session.commit()
    return redirect(url_for('checkPage'))
Esempio n. 2
0
def sendMessage():
    account = request.values.get("account")
    toAccount = request.values.get("toAccount")
    description = request.values.get("description")
    user = db.session.query(User).filter_by(account=account).first()
    new_message = Message(account=toAccount,
                          fromAccount=account,
                          description=description,
                          time=datetime.datetime.now(),
                          username=user.username,
                          userAvatarUrl=user.avatarUrl)
    db.session.add(new_message)
    db.session.commit()
    return "ok"
def send_message(recipient):
    user = User.query.filter_by(username=recipient).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        msg = Message(author=current_user,
                      recipient=user,
                      body=form.message.data)
        db.session.add(msg)
        db.session.commit()
        flash('Your message has been sent', 'success')
        return redirect(url_for('main.home', username=recipient))
    return render_template('send_message.html',
                           title='Send Message',
                           form=form,
                           recipient=recipient)
Esempio n. 4
0
def reportVideo():
    account = request.values.get("account")
    videoID = request.values.get("videoID")
    description = request.values.get("description")
    # 先改video表里的状态
    video = db.session.query(Video).filter_by(id=videoID).first()
    video.state = "被举报"
    # 再添加消息
    new_message = Message(account=video.account,
                          fromAccount="official",
                          description="你的视频被举报,原因:" + description,
                          time=datetime.datetime.now(),
                          username="******",
                          userAvatarUrl="static/avatars/officialavatar.jpg")
    db.session.add(new_message)
    db.session.commit()
    return "ok"
Esempio n. 5
0
def message_ex_old(uid, fid, eid):
    if current_user.id == int(eid):
        m = Message()
        ums = Message.query.filter(Message.uid == uid, Message.fid == fid,
                                   Message.eid == eid).order_by(
                                       Message.timestamp)
        eicon = User.query.filter(User.id == int(eid)).first().icon
        uicon = User.query.filter(User.id == int(uid)).first().icon
        content = request.form.get('text')
        if request.method == 'POST' and content:
            m.fid = int(fid)
            m.uid = int(uid)
            m.eid = int(eid)
            m.name = current_user.username  # 发消息的人
            m.timestamp = time.strftime("%Y-%m-%d %H:%M:%S")  # 发送时间
            f = UserFiles.query.filter(UserFiles.id == int(fid)).first()
            m.title = f.fileTitle
            m.content = content  # 消息内容
            m.expert = True  # 是专家发言
            m.save()
        return render_template('expertcenter/message_old.html',
                               ums=ums,
                               eicon=eicon,
                               uicon=uicon)
    else:
        return render_template('common/nocan.html', u=current_user.username)
Esempio n. 6
0
def message_ex(uid, fid, eid):
    if current_user.id == int(eid):
        # 判断对方是否存在
        if not User.query.filter(User.id == int(uid)).first():
            return render_template('common/nonentity.html')
        else:
            m = Message()
            ums = Message.query.filter(
                Message.uid == int(uid), Message.fid == int(fid),
                Message.eid == int(eid)).order_by(Message.timestamp)
            # 页面最多显示信息条数
            num = 30
            # off 偏移量 跳过这么多数据再去查询
            off = len(ums.all()) - num
            if off > 0:
                showums = ums.offset(off)
            else:
                showums = ums.offset(0)
            content = request.form.get('text')
            eicon = User.query.filter(User.id == int(eid)).first().icon
            uicon = User.query.filter(User.id == int(uid)).first().icon

            if request.method == 'POST' and content:
                m.fid = int(fid)
                m.uid = int(uid)
                m.eid = int(eid)
                m.name = current_user.username  # 发消息的人
                m.timestamp = time.strftime("%Y-%m-%d %H:%M:%S")  # 发送时间
                f = UserFiles.query.filter(UserFiles.id == int(fid)).first()
                m.title = f.fileTitle
                m.content = content  # 消息内容
                m.expert = True  # 是专家发言
                m.save()
            return render_template('expertcenter/message.html',
                                   ums=showums,
                                   eicon=eicon,
                                   uicon=uicon)
    else:
        return render_template('common/nocan.html', u=current_user.username)
Esempio n. 7
0
    def post(self):
        user=g.user
        args = parse_room_message.parse_args()

        roomid = args.get("roomid")
        room=Room.query.get(roomid)
        if room is None:
            abort(404, msg="room don't exit")

        picture = request.files.get("picture")
        if picture is None:
            abort(404, msg="请上传图片")
        try:
            picture.filename = secure_filename(picture.filename)
            picture.filename = change_filename(picture.filename)
            picture.filename = str(user.id) + picture.filename
            filepath = PIC_DIR + picture.filename
            picture.save(filepath)
        except:
            abort(401,"图片上传失败")
        message = Message()
        message.body = "http://39.106.119.191/uploads/pictures/"+picture.filename
        message.type = 2
        message.message_author = user.id
        message.message_room = roomid
        message.from_user = user.username
        message.user_icon = user.icon
        message.timestamp = datetime.now()
        message.save()

        for name, u_socket in user_socket_dict[roomid].items():
            try:
                data = dict(marshal(message, message_fields))
                u_socket.send(str(data))
            except Exception:
                pass
Esempio n. 8
0
    def get(self):
        user = g.user
        # print(user.id)
        usr_socket = request.environ.get("wsgi.websocket")  # type:WebSocket
        # print(usr_socket)
        # 查询用户的房间 并添加到通讯字典
        for room in user.rooms:
            if usr_socket:
                addtwodimdict(user_socket_dict, room.id, user.username, usr_socket)
                # 添加到通讯字典的同时,发送给该房间所有人上线信息
                for name, u_socket in user_socket_dict[room.id].items():
                    data = {
                        "status": HTTP_OK,
                        "num": len(user_socket_dict[room.id]),
                        "is_online": 1,
                        "username": user.username,
                        "roomid":room.id,
                        "type":0,
                    }
                    try:
                        u_socket.send(str(data))
                    except WebSocketError as e:
                        print(user_socket_dict)
                        if user.username in user_socket_dict[room.id]:
                            del user_socket_dict[room.id][user.username]
                        print(e)
                        return

        # print(user_socket_dict)
        while True:
            try:
                msg = usr_socket.receive()
                print(msg)
            except:
                for room in user.rooms:
                    if user.username in user_socket_dict[room.id]:
                        del user_socket_dict[room.id][user.username]
                    for name, u_socket in user_socket_dict[room.id].items():
                        data = {
                            "status": HTTP_OK,
                            "num": len(user_socket_dict[room.id]),
                            "is_online": 0,
                            "username": user.username,
                        }
                        u_socket.send(str(data))
                break


            # break

            if msg is None:
                for room in user.rooms:
                    if user.username in user_socket_dict[room.id]:
                        del user_socket_dict[room.id][user.username]
                    for name, u_socket in user_socket_dict[room.id].items():
                        data = {
                            "status": HTTP_OK,
                            "num": len(user_socket_dict[room.id]),
                            "is_online": 0,
                            "username": user.username,
                        }
                        u_socket.send(str(data))
                break

            if msg:
                # print(msg)

                try:
                    msg = eval(msg)
                except:
                    break


                if msg.get("type") == 0:
                #登录
                    is_online = msg.get("is_online")
                #登出
                    if is_online == 0:
                        for room in user.rooms:
                            if user.username in user_socket_dict[room.id]:
                                del user_socket_dict[room.id][user.username]
                            for name, u_socket in user_socket_dict[room.id].items():
                                data = {
                                    "status": HTTP_OK,
                                    "num": len(user_socket_dict[room.id]),
                                    "is_online": is_online,
                                    "username":user.username,
                                }
                                u_socket.send(str(data))

                    if is_online == 0:
                        break


                # 发送文字信息
                if msg.get("type") == 1:
                    message = Message()
                    message.body = msg.get('msg')
                    message.type = msg.get("type")

                    roomid = msg.get("roomid")
                    room = Room.query.get(roomid)
                    if room is None:
                        abort(400, msg="请提供正确的roomid")

                    message.message_author = user.id
                    message.message_room = room.id
                    message.from_user = user.username
                    message.user_icon = user.icon
                    # print(datetime.now())
                    message.timestamp = datetime.now()
                    message.save()

                    for name, u_socket in user_socket_dict[room.id].items():
                        try:

                            data = dict(marshal(message, message_fields))

                            u_socket.send(str(data))
                            # print("sended")

                        except WebSocketError as e:
                            print(user_socket_dict)
                            print(e)
                            if user.username in user_socket_dict[room.id]:
                                del user_socket_dict[room.id][user.username]
                            break