示例#1
0
def get_secret_message():
    user_f = int(request.args.getlist('from')[0])
    user_t = int(request.args.getlist('to')[0])
    try:
        msg = Message.objects(members__all=[user_f, user_t]).first().content
        return flask_succ_template_fun({'type': 'secret', 'data': msg})
    except:
        return flask_succ_template_fun({'type': 'secret', 'data': []})
示例#2
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            return flask_error_template_fun({'error': 'no file input'})
        file = request.files['file']
        if file.filename == '':
            return flask_error_template_fun({'error': 'no file input'})
        if file:
            filename = request.form['filename']
            file.save(os.path.join(UPLOAD_FOLDER_FILE, filename))
            return flask_succ_template_fun({'msg': str(filename)})
        else:
            return flask_succ_template_fun({'msg': 'illegal file format'})
示例#3
0
def get_msg_lsit():
    userid = int(request.args.getlist('userid')[0])
    msgs = Message.objects(members__in=[userid])
    data = []
    for i in msgs:
        if i.msg_type == 0:
            one = {}
            members = i.members
            members.remove(userid)
            one['userid'] = int(members[0])
            time_raw = i.content[-1]['time']
            time = time_raw.split(" ")[1]
            one['time'] = time
            one['name'] = get_name(one['userid'])
            one['message'] = i.content[-1]['msg']
            data.append(one)
        else:
            one = {}
            one['userid'] = int(i.msg_type)
            time_raw = i.content[-1]['time']
            time = time_raw.split(" ")[1]
            one['time'] = time
            one['name'] = get_name(one['userid'])
            one['message'] = i.content[-1]['msg']
            data.append(one)
    return flask_succ_template_fun(data)
示例#4
0
def friend():
    userid = int(request.form['userid'])
    f = User.objects.filter(userid=userid).first().friends
    data = []
    for i in f:
        data.append({'userid': i, 'name': get_name(i)})
    return flask_succ_template_fun(data)
示例#5
0
def get_group_list():
    userid = int(request.args.getlist('userid')[0])
    user = User.objects.filter(userid=userid).first()
    grps = Group.objects(members__in=[userid])
    data = []
    for i in grps:
        data.append({'userid': i.groupid, 'name': i.name})
    return flask_succ_template_fun(data)
示例#6
0
def get_userdata():
    userid = int(request.form['userid'])
    user = User.objects.filter(userid=userid).first()
    return flask_succ_template_fun({
        'userid': user.userid,
        'name': user.name,
        'sex': user.sex
    })
示例#7
0
def get_id():
    name = request.form['name']
    user = User.objects.filter(name=name)
    if len(user) != 0:
        user_id = int(user.first().userid)
        return flask_succ_template_fun({'id': user_id})
    else:
        return flask_error_template_fun({'msg': '查无此用户'})
示例#8
0
def get_group_message():
    groupid = int(request.args.getlist('groupid')[0])
    # try:
    msg = Message.objects.filter(msg_type=groupid).first().content
    msg2 = []
    for i in msg:
        one = i.copy()
        one['name'] = get_name(i['userid'])
        msg2.append(one)
    return flask_succ_template_fun({'type': 'secret', 'data': msg2})
示例#9
0
def login():
    name = request.form['name']
    password = request.form['password']
    user = User.objects.filter(name=name)
    if len(user) == 0:
        return flask_error_template_fun({'msg': '没有此用户'})
    else:
        user_t = user.first()
        if check_password_hash(user_t.password, password):
            return flask_succ_template_fun({'msg': '登录成功'})
        else:
            return flask_error_template_fun({'msg': '密码错误'})
示例#10
0
def add_friend():
    userid = int(request.form['userid'])
    friend = int(request.form['friend'])
    user = User.objects.filter(userid=userid).first()
    user2 = User.objects.filter(userid=friend).first()
    user_f = user.friends
    user_f.append(user2.userid)
    user_f = list(set(user_f))
    user.update(friends=user_f)
    friend_f = user2.friends
    friend_f.append(user.userid)
    friend_f = list(set(friend_f))
    user2.update(friends=friend_f)
    return flask_succ_template_fun({'msg': '添加成功'})
示例#11
0
def enter_group():
    userid = int(request.form['userid'])
    groupid = int(request.form['groupid'])
    group = Group.objects.filter(groupid=groupid)
    if len(group) != 0:
        the_group = group.first()
        members = the_group.members
        if userid in members:
            return flask_succ_template_fun({'msg': '不要重复加入'})
        else:
            try:
                msg = Message.objects(members__all=members).first()
                mem = members
                members.append(userid)
                msg.update(members=mem)
            except:
                pass

            members.append(userid)
            the_group.update(members=members)
            return flask_succ_template_fun({'msg': '加入成功'})
    else:
        return flask_succ_template_fun({'msg': '加入失败'})
示例#12
0
def add_group():
    userid = int(request.form['userid'])
    name = request.form['name']
    new_group = Group(name=name, members=[userid])
    new_group.save()
    return flask_succ_template_fun({'msg': str(new_group.groupid)})