示例#1
0
def login(recvc_dic, conn):
    user_list = models.User.select(name=recvc_dic['name'])
    if user_list:
        user_obj = user_list[0]
        if user_obj.user_type == recvc_dic['user_type']:
            if user_obj.password == recvc_dic['password']:
                send_dic = {'flag': True, 'msg': '登陆成功'}
                # session
                session = common.get_session()
                send_dic['session'] = session
                mutex.acquire()
                user_date.alive_dic[recvc_dic['addr']] = [
                    session, user_obj.id
                ]  # 保护数据
                mutex.release()
                # 后期加公告
                new_notice = user_interface.notice_by_count(1)[0]
                send_dic['new_notice'] = new_notice
                send_dic['is_vip'] = user_obj.is_vip
            else:
                send_dic = {'flag': False, 'msg': '两次密码不一致'}
        else:
            send_dic = {'flag': False, 'msg': '用户类型不一致'}
    else:
        send_dic = {'flag': False, 'msg': '用户不存在'}
    common.send_msg(send_dic, conn)
示例#2
0
def upload_movie(recv_dic,conn):
    # 电影是已经纯在的 直接上他
    file_name = common.get_session() + recv_dic['movie_name']
    file_size = recv_dic['file_size']

    path = os.path.join(setttings.UPLOAD_MOVIE_PATH,file_name)

    movie_obj = models.Movie(name=file_name,
                 path=path,
                 is_free=recv_dic['is_free'],
                 file_md5=recv_dic['file_md5'],
                 is_delete=0,
                 upload_time=common.get_time(),
                 user_id=recv_dic['user_id'])

    # 写文键
    recv_size= 0
    with open(path,'wb')as f:
        while recv_size<file_size:
            data = conn.recv(1024)
            f.write(data)
            recv_size += len(data)
        print('下载成功')


    send_dic = {"flag":True,'msg':'上传成功'}

    movie_obj.save()
    common.send_msg(send_dic,conn)
示例#3
0
def login_interface(user_dic, conn):
    user_list = models.User.select_sql(user_name=user_dic.get("user_name"))
    if user_list:
        user_obj = user_list[0]
        user_name = user_obj.get("user_name")
        pwd = user_dic.get("pwd")
        if user_obj.pwd == common.get_pwd_md5(pwd):

            session = common.get_session(user_name)
            addr = user_dic.get("addr")
            user_data.mutex.acquire()
            user_data.online_user[addr] = [session, user_obj.user_id]
            user_data.mutex.release()
            print(user_data.online_user)
            send_dic = {
                "flag": True,
                "msg": "登陆成功",
                "session": session,
                "is_vip": user_obj.is_vip
            }
            common.send_msg(send_dic, conn)
        else:
            send_dic = {
                "flag": False,
                "msg": "登陆失败",
            }
            common.send_msg(send_dic, conn)
    else:
        send_dic = {
            "flag": False,
            "msg": "登陆失败",
        }
        common.send_msg(send_dic, conn)
示例#4
0
def login(back_dic, conn):
    user_list = models.User.select(name=back_dic.get('name'))
    user_obj = user_list[0]
    if user_list:
        if back_dic.get('user_type') == user_obj.user_type:
            if back_dic.get('password') == user_obj.password:
                send_dic = {'flag': True, 'msg': '登录成功!'}
                session = common.get_session(back_dic.get('name'))
                user_data.mutex.acquire()
                user_data.alive_user[back_dic.get('addr')] = [
                    session, user_obj.id
                ]
                user_data.mutex.release()
                send_dic['session'] = session
                send_dic['is_vip'] = user_obj.is_vip
                # 普通用户加公告
                if back_dic.get('user_type') == 'user':
                    notice = user_interface.get_notice_list(1)
                    send_dic['notice'] = notice
            else:
                send_dic = {'flag': False, 'msg': '密码错误,请确认!'}
        else:
            send_dic = {'flag': False, 'msg': '当前用户不是被许可登录的类型!'}
    else:
        send_dic = {'flag': False, 'msg': '当前用户不存在!'}
    common.send_msg(send_dic, conn)
示例#5
0
def upload_movie_interface(back_dic, conn):

    # 1.服务端接收客户端传入的文件
    # 获取电影大小,用于接收
    movie_size = back_dic.get('movie_size')
    movie_name = back_dic.get('movie_name')

    # wagohawoighwioaghwoagjwa + 电影的名字.mp4
    movie_new_name = common.get_session(movie_name) + movie_name

    movie_path = os.path.join(settings.DOWNLOAD_MOVIES_PATH, movie_new_name)

    recv_data = 0
    with open(movie_path, 'wb') as f:
        while recv_data < movie_size:
            data = conn.recv(1024)
            f.write(data)
            recv_data += len(data)

    # 2.存储电影信息于电影表中
    movie_obj = Models.Movie(movie_name=movie_new_name,
                             is_free=back_dic.get('is_free'),
                             is_delete=0,
                             file_md5=back_dic.get('movie_md5'),
                             path=movie_path,
                             upload_time=datetime.datetime.now(),
                             user_id=back_dic.get('user_id'))

    movie_obj.save()

    send_dic = {'flag': True, 'msg': '电影上传成功!'}

    common.send_msg(send_dic, conn)
def login_interface(back_dic, conn):
    """
    用户登录接口
    :param back_dic:
    :param conn:
    """
    username = back_dic.get('username')
    pwd = back_dic.get('pwd')

    user_pwd = common.get_md5(pwd)

    user_obj = Models.UserInfo.sql_select(user_name=username)

    # 在服务器中保存session信息
    addr = back_dic.get('addr')

    if user_obj:
        user_obj = user_obj[0]
        # 判断密码是否相同
        if user_obj.user_pwd == user_pwd:
            send_dic = {
                'flag': True,
                'msg': '登录成功',
                'is_vip': user_obj.is_vip,
                'new_notice': None
            }

            session = common.get_session(username)

            send_dic['session'] = session

            # 将登录信息保存到online_info中
            lock.acquire()

            user_data.online_info[addr] = [session, user_obj.user_id]  # 保存,session 和用户id用户登录验证

            lock.release()

            # 获取最新公告
            new_notice = common_interface.get_new_notice_interface()
            send_dic['new_notice'] = new_notice

        else:
            send_dic = {
                'flag': False,
                'msg': '用户名或密码错误'
            }
    else:
        send_dic = {
            'flag': False,
            'msg': '用户不存在,还不去注册去'
        }
    # {"('127.0.0.1', 63696)": ['104207c87d76dba69375219c4909eb85', 1]}
    # print(user_data.online_info)

    # print(user_data.mutex)

    common.send_msg(send_dic, conn)
示例#7
0
def login_interface(back_dic,):
    username = back_dic.get('username')
    usertype = back_dic.get('user_type')
    # 判断用户是否存在
    user_list = User(name=username).select(whereStr ="name = {} and user_type = '{}' ".format(username,str(usertype)))

    if user_list:
        user_obj = user_list[0]
        password = back_dic.get('password')
        # 判断密码是否正确
        if common.get_md5(password) == user_obj.password:

            # 登录成功后记录状态
            # cookies, session
            # 一个加密后的随机字符串
            session = common.get_session(username)

            addr = back_dic.get('addr')

            # 保存session到服务端
            # [session, user_obj.user_id]  # [afwagawgwaawgwaga, 1]
            # 把用户session字符串与id写入user_data文件中
            # user_data.mutex.acquire()
            user_data.online_user[addr] = [session, user_obj.id]
            # user_data.mutex.release()

            send_dic = {
                'flag': True,
                'msg': '登录成功',
                'id': user_obj.id,
                'session': session,
                'is_vip': user_obj.is_vip
            }
        else:
            send_dic = {
                'flag': False,
                'msg': '密码错误'
            }
    else:
        send_dic = {
            'flag': False,
            'msg': '用户不存在!'
        }
    return send_dic
示例#8
0
def login_interface(recv_dict, conn):
    # 1.判断用户是否存在
    username = recv_dict.get('username')
    # 1.判断用户是否存在 ---接收到--->[{}]  列表套字典
    user_obj_list = models.User.orm_select(username=username)

    # 2.没有值--->用户不存在
    if not user_obj_list:
        send_dict = {'flag': False, 'msg': '用户不存在'}
    # 1.用户存在的情况
    else:
        user_obj = user_obj_list[0]
        # 2.判断密码是否正确
        re_password = recv_dict.get('password')  # 用户输入的密码
        re_password = common.md5(re_password)
        mysql_password = user_obj.password  # 数据库存的真正密码

        # 密码正确
        if re_password == mysql_password:
            addr = recv_dict.get('addr')
            mutex.acquire()  # 加锁
            # 用户登录成功后,获取session值
            session = common.get_session()
            # 给session字典添加值   {地址:[session,用户id]}这样session值就是唯一
            session_dict[addr] = [session, user_obj.u_id]
            mutex.release()  # 释放锁

            # 默认不是VIP
            is_vip = False
            if user_obj.is_vip:
                is_vip = True
            send_dict = {
                'flag': True,
                'msg': '登录成功!',
                'session': session,
                'is_vip': is_vip
            }

        # 密码不正确
        else:
            send_dict = {'flag': False, 'msg': '密码错误!'}
    # 调用接口发送反馈信息字典
    common.send_dict(send_dict, conn)
示例#9
0
def login(user_dic,conn):
    user=models.User.select_one(name=user_dic['name'])
    if user:
        if user.user_type==user_dic['user_type']:
            if user.password==user_dic['password']:
                session=common.get_session(user_dic['name'])
                user_data.mutex.acquire()
                if user_dic['addr'] in user_data.alive_user:
                    user_data.alive_user.pop(user_dic['addr'])
                user_data.alive_user[user_dic['addr']]=[session,user.id]
                user_data.mutex.release()
                back_dic={'flag':True,'msg':'user:%s login successfully'%user_dic['name'],'session':session,'is_vip':user.is_vip}
                if user_dic['user_type']=='user':
                    back_dic['notice']=user_interface.check_notice_by_count(1)
            else:
                back_dic={'flag':False,'msg':'password differ'}
        else:back_dic={'flag':False,'msg':'user type error'}
    else:
        back_dic={'flag':False,'msg':'username does not exist'}
    common.send_back(back_dic,conn)
示例#10
0
def show():
    search_text = request.args.get('q', '').strip()
    search_type = request.args.get('type', 'rule34').strip()

    if search_text == '':
        return jsonify({'message': 'Missing search query ("q" query param)'},
                       status=400)

    if search_type not in search_types:
        return jsonify({'message': 'Invalid search type.'}, status=400)

    search_url = search_types[search_type]['url'].format(search_text)
    s = get_session()
    response = s.get(search_url)

    if search_types[search_type].get('format', 'json') == 'xml':
        posts = [x.attrib for x in parsexml(response.text).findall('post')]
    else:
        posts = response.json()['posts']

    return jsonify(posts)
示例#11
0
def upload_movie(user_dic, conn):
    recv_size = 0
    file_name = common.get_session(
        user_dic['file_name']) + user_dic['file_name']
    path = os.path.join(settings.BASE_MOVIE_LIST, file_name)
    with open(path, 'wb') as f:
        while recv_size < user_dic['file_size']:
            data = conn.recv(1024)
            f.write(data)
            recv_size += len(data)
    movie = models.Movie(name=file_name,
                         path=path,
                         user_id=user_dic['user_id'],
                         file_size=user_dic['file_size'],
                         file_md5=user_dic['file_md5'],
                         is_free=user_dic['is_free'])
    movie.save()
    back_dic = {
        'flag': True,
        'msg': 'movie:%s upload successfully' % (user_dic['file_name'])
    }
    common.send_back(back_dic, conn)
示例#12
0
def upload_movie(back_dic, conn):
    file_name = common.get_session(
        back_dic.get('file_name')) + back_dic.get('file_name')
    file_size = back_dic.get('file_size')
    file_md5 = back_dic.get('file_md5')
    is_free = back_dic.get('is_free')
    file_path = os.path.join(settings.MOVIE_DIR, file_name)
    recv_size = 0
    with open(file_path, 'wb') as f:
        while recv_size < file_size:
            recv_data = conn.recv(1024)
            f.write(recv_data)
            recv_size += len(recv_data)
    movie_obj = models.Movie(name=file_name,
                             path=file_path,
                             is_free=is_free,
                             is_delete=0,
                             file_md5=file_md5,
                             upload_time=common.get_now_time(),
                             user_id=back_dic.get('user_id'))
    movie_obj.insert()
    send_dic = {'flag': True, 'msg': '上传成功'}
    common.send_msg(send_dic, conn)
示例#13
0
def login_interface(back_dic, conn):
    username = back_dic.get('username')
    # 判断用户是否存在
    user_list = Models.User.select(user_name=username)
    if user_list:
        user_obj = user_list[0]
        password = back_dic.get('password')
        # 判断密码是否正确
        if common.get_md5(password) == user_obj.pwd:

            # 登录成功后记录状态
            # cookies, session
            # 一个加密后的随机字符串
            session = common.get_session(username)

            addr = back_dic.get('addr')

            # 保存session到服务端
            # [session, user_obj.user_id]  # [afwagawgwaawgwaga, 1]
            # 把用户session字符串与id写入user_data文件中
            user_data.mutex.acquire()
            user_data.online_user[addr] = [session, user_obj.user_id]
            user_data.mutex.release()

            send_dic = {
                'flag': True,
                'msg': '登录成功',
                'session': session,
                'is_vip': user_obj.is_vip
            }

        else:
            send_dic = {'flag': False, 'msg': '密码错误'}
    else:
        send_dic = {'flag': False, 'msg': '用户不存在!'}
    common.send_msg(send_dic, conn)
示例#14
0
def login_interface(back_dic, conn):
    username = back_dic.get('username')
    password = back_dic.get('password')
    # user_type = back_dic.get('user_type')
    user_obj_list = models.User.orm_select(username=username)
    if not user_obj_list:
        send_dic = {'flag': False, 'msg': '用户名不存在'}
    else:

        user_obj = user_obj_list[0]
        print(user_obj.password)
        if user_obj.password != password:

            send_dic = {'flag': False, 'msg': '密码不正确'}
        else:
            session_lock.acquire()
            session = common.get_session()
            u_id = user_obj.u_id
            session_data.session_dic[back_dic.get('addr')] = [session, u_id]
            session_lock.release()

            send_dic = {'flag': True, 'msg': '登录成功', 'session': session}

    common.send_data(send_dic, conn)