コード例 #1
0
ファイル: app_server.py プロジェクト: HMQstu/FileServer
def register():
    """
用户注册
    :return:
    """
    res = CommonRes()
    username = request.form['username']
    password = request.form['password']
    # role 取值:normal 普通, leader 领导, admin 管理员
    role = request.form['role']
    mail = request.form['mail']
    phone = request.form['phone']

    if username == '' or password == '' or role == '':
        res.code = -1
        res.message = 'invalid params'
        return json_utils.to_json_res(res)

    u = User()
    u.username = username
    u.password = password
    if 'admin' == role:
        u.role = permission_manager.ROLE_ADMIN
    elif 'leader' == role:
        u.role = permission_manager.ROLE_LEADER
    else:
        u.role = permission_manager.ROLE_NORMAL
    u.mail = mail
    u.phone = phone

    user_service.register_user(u)
    res.code = 0
    res.message = 'success'
    res.data = u
    return json_utils.to_json_res(res)
コード例 #2
0
ファイル: app_server.py プロジェクト: HMQstu/FileServer
def upload():
    res = CommonRes()
    if 'user' not in session:
        res.code = -3
        res.message = 'no user login'
        return json_utils.to_json_res(res)
    user_dict = session['user']
    file_io = request.files['file']
    files_permission = int(str(request.form['permission']))
    text = request.form['text']
    result = file_service.insert_new_file(file_io, user_dict['username'],
                                          files_permission)
    if result is not None:
        res.code = 0
        res.message = 'success'
        res.data = result
    else:
        res.code = -1
        res.message = 'error'
    return json_utils.to_json_res(res)
コード例 #3
0
ファイル: app_server.py プロジェクト: HMQstu/FileServer
def delete_file():
    """
删除文件,传参: id 文件id号 int
    :return:
    """
    res = CommonRes()
    if 'user' not in session:
        res.code = -3
        res.message = 'no user login'
        return json_utils.to_json_res(res)
    user_dict = session['user']
    role = int(user_dict['role'])
    file_id = int(request.values['id'])
    result = file_service.drop_file(file_id, role)
    if result == 0:
        res.code = 0
        res.message = 'success'
    elif result == -3:
        res.code = -3
        res.message = 'permission denied'
    else:
        res.code = -1
        res.message = 'no such file'
    return json_utils.to_json_res(res)
コード例 #4
0
ファイル: app_server.py プロジェクト: HMQstu/FileServer
def login():
    """
用户登录  
    :return:
    """
    res = CommonRes()
    username = request.form['username']
    password = request.form['password']
    if username is None or password is None:
        res.code = -1
        res.message = 'invalid params'
        return json_utils.to_json_res(res)
    user = user_service.query_user(username, password)
    if user is None:
        res.code = -2
        res.message = 'username or password not correct'
        return json_utils.to_json_res(res)
    session['user'] = user.__dict__
    res.code = 0
    res.message = 'success'
    res.data = user
    return json_utils.to_json_res(res)
コード例 #5
0
ファイル: app_server.py プロジェクト: HMQstu/FileServer
def query_files():
    res = CommonRes()
    if 'user' not in session:
        res.code = -3
        res.message = 'no user login'
        return json_utils.to_json_res(res)
    user_dict = session['user']
    role = int(user_dict['role'])
    key_word = request.values['key']
    result = search_service.query_files(role, key_word)

    res.code = 0
    res.message = 'success'
    res.data = result
    return json_utils.to_json_res(res)
コード例 #6
0
ファイル: app_server.py プロジェクト: HMQstu/FileServer
def logout():
    """
注销用户
    :return:
    """
    res = CommonRes()
    res.code = -3
    res.message = 'no user login'
    if 'user' in session:
        old_user = session['user']
        session.pop('user', None)
        res.code = 0
        res.message = 'success'
        res.data = old_user
    return json_utils.to_json_res(res)
コード例 #7
0
ファイル: app_server.py プロジェクト: HMQstu/FileServer
def files():
    res = CommonRes()
    if 'user' not in session:
        res.code = -3
        res.message = 'no user login'
        return json_utils.to_json_res(res)
    user_dict = session['user']
    role = int(user_dict['role'])
    files_list = file_service.visible_files_list(role)
    result = [
        simple_file_info.parse(x, role, user_dict['username'])
        for x in files_list
    ]

    res.code = 0
    res.message = 'success'
    res.data = result
    return json_utils.to_json_res(res)