예제 #1
0
def login(message, conn):
    name = message['name']
    password = message['password']
    user = models.UserInfo.select_one(name=name)
    if user:
        if user.user_type == message['user_type']:
            if user.password == password:
                send_dic = {
                    'flag': True,
                    'msg': '%s:%s 登录成功' % (user.user_type, name)
                }
                session = common.get_md5(name, password)
                send_dic['session'] = session
                print(user_info.live_user, '<==')
                user_info.mutex.acquire()
                user_info.live_user[message['addr']] = [session, user.id]
                user_info.mutex.release()
                print(user_info.live_user, '<==')
            else:
                send_dic = {
                    'flag': False,
                    'msg': '%s:%s 密码错误!' % (user.user_type, name)
                }
        else:
            send_dic = {
                'flag': False,
                'msg': '%s不是%s用户!' % (user.name, message['user_type'])
            }
    else:
        send_dic = {
            'flag': False,
            'msg': '%s:%s 不存在!' % (message['user_type'], name)
        }
    common.send_message(send_dic, conn)
예제 #2
0
def check_movie_list(message, conn):
    movie_obj_list = models.Movie.select_many()

    if movie_obj_list:
        back_movie = list()
        for movie_obj in movie_obj_list:
            if movie_obj.is_delete == 0:
                if message['movie_type'] == 'all':
                    back_movie.append([
                        movie_obj.name, '免费' if movie_obj.is_free else '收费',
                        movie_obj.id
                    ])
                elif message['movie_type'] == 'free':
                    if movie_obj.is_free == 1:
                        back_movie.append([movie_obj.name, '免费', movie_obj.id])
                else:
                    if movie_obj.is_free == 0:
                        back_movie.append([movie_obj.name, '收费', movie_obj.id])

        if back_movie:
            send_dic = {'flag': True, 'msg': back_movie}
        else:
            send_dic = {'flag': False, 'msg': '暂无电影!'}
    else:
        send_dic = {'flag': False, 'msg': '暂无电影!'}

    common.send_message(send_dic, conn)
예제 #3
0
def upload_movie(message, conn):
    file_size = message['file_size']
    file_name = message['file_name']
    create_time = message['create_time']
    file_md5 = message['file_md5']
    is_free = message['is_free']
    is_delete = message['is_delete']
    file_path = os.path.join(settings.BASE_MOVIES_TRUE_DIR, file_name)
    start_size = 0
    with open(file_path, 'wb') as f:
        while start_size < file_size:
            data = conn.recv(1024)
            f.write(data)
            start_size += len(data)
        f.flush()

    movie = models.Movie(
        name=file_name,
        path=file_path,
        is_free=is_free,
        is_delete=is_delete,
        create_time=create_time,
        user_id=message['user_id'],
        file_md5=file_md5,
    )
    movie.save()
    send_dic = {'flag': True, 'msg': '%s上传成功' % file_name}
    common.send_message(send_dic, conn)
예제 #4
0
def delete_file(message, conn):
    print(message)
    file_id = message['file_id']
    file_obj = models.Movie.select_one(id=file_id)
    file_obj.is_delete = 1
    file_obj.update()
    file_name = file_obj.name
    send_dic = {'flag': True, 'msg': '%s删除成功!' % file_name}
    common.send_message(send_dic, conn)
예제 #5
0
def buy_member(message, conn):
    id = message['user_id']
    user_obj = models.UserInfo.select_one(id=id)
    user_obj.is_vip = 1
    user_obj.update()
    send_dic = {
        'flag': 'True',
        'msg': '%s:%s开通会员成功!' % (user_obj.user_type, user_obj.name)
    }
    common.send_message(send_dic, conn)
예제 #6
0
def release_notice(message, conn):
    name = message['name']
    content = message['content']
    create_time = message['create_time']
    user_id = message['user_id']
    notice = models.Notice(name=name,
                           content=content,
                           create_time=create_time,
                           user_id=user_id)
    notice.save()
    send_dic = {'flag': True, 'msg': '公告发布成功!'}
    common.send_message(send_dic, conn)
예제 #7
0
def register(message, conn):
    name = message['name']
    user = models.UserInfo.select_one(name=name)
    if user:
        send_dic = {
            'flag': False,
            'msg': '%s:%s 已经存在!' % (message['user_type'], user.name)
        }
    else:
        user = models.UserInfo(
            name=name,
            password=message['password'],
            is_vip=message['is_vip'],
            locked=message['locked'],
            user_type=message['user_type'],
        )
        user.save()
        send_dic = {
            'flag': True,
            'msg': '%s:%s 注册成功!' % (message['user_type'], user.name)
        }
    common.send_message(send_dic, conn)
예제 #8
0
def distribute(message, conn):
    if message['type'] in func_dic:
        func_dic[message['type']](message, conn)
    else:
        send_dic = {'flag': False, 'msg': '分发函数找不到函数对象'}
        common.send_message(send_dic, conn)