Beispiel #1
0
def delete_tool(enum):
    try:
        access_tools = UserService().get_tools_user(session)
        UserService().delete_tool(access_tools, enum)
        tool_json = ToolService().delete_tool(enum, access_tools)
        data = dict({
            "title": "Tool is deleted",
            "subTitle": "Tool Info: {}".format(json.dumps(tool_json))
        })
        status = 200
    except REST_Exception as e:
        data = dict({
            "title": "Server Error",
            "subTitle": "Logs: {}".format(str(e))
        })
        status = e.status
    return get_response_json(data, status)
Beispiel #2
0
def add_tool():
    try:
        UserService().assert_logged_in(session)
        req_dict = json.loads(request.data)
        req_dict = ToolService().add_tool(req_dict)
        UserService().add_tool_to_user(session, req_dict["enum"])
        data = dict({
            "title": "Tool is added to the proxy",
            "subTitle": "Tool Info: {}".format(json.dumps(req_dict))
        })
        status = 200
    except REST_Exception as e:
        traceback.print_exc()
        data = dict({
            "title": "Server Error",
            "subTitle": "Logs: {}".format(str(e))
        })
        status = e.status
    return get_response_json(data, status)
Beispiel #3
0
def get_users():
    try:
        data = UserService().get_users(session)
        status = 200
    except REST_Exception as e:
        data = dict({
            "title": "Server Error",
            "subTitle": "Logs: {}".format(str(e))
        })
        status = e.status
    return get_response_json(data, status)
Beispiel #4
0
def list_all_tools():
    try:
        access_tools = UserService().get_tools_user(session)
        data = ToolService().list_all_tools(access_tools)
        status = 200
    except REST_Exception as e:
        traceback.print_exc()
        data = dict({
            "title": "Server Error",
            "subTitle": "Logs: {}".format(str(e))
        })
        status = e.status
    return get_response_json(data, status)
Beispiel #5
0
def isauth_user():
    try:
        UserService().assert_logged_in(session)
        data = dict({
            "title": "Authenticated",
        })
        status = 200
    except REST_Exception as e:
        data = dict({
            "title": "Server Error",
            "subTitle": "Logs: {}".format(str(e))
        })
        status = e.status
    return get_response_json(data, status)
Beispiel #6
0
def delete_user(username):
    try:
        UserService().delete_user(username, session)
        data = dict({
            "title": "User is successfully deleted",
        })
        status = 200
    except REST_Exception as e:
        data = dict({
            "title": "Server Error",
            "subTitle": "Logs: {}".format(str(e))
        })
        status = e.status
    return get_response_json(data, status)
Beispiel #7
0
def update_other_user(username):
    try:
        req_dict = json.loads(request.data)
        user = UserService().update_other_user(username, req_dict, session)
        data = dict({
            "title": "Update success",
        })
        status = 200
    except REST_Exception as e:
        data = dict({
            "title": "Server Error",
            "subTitle": "Logs: {}".format(str(e))
        })
        status = e.status
    return get_response_json(data, status)
Beispiel #8
0
def update_tool(enum):
    try:
        access_tools = UserService().get_tools_user(session)
        req_dict = json.loads(request.data)
        req_dict = ToolService().update_tool(req_dict, enum, access_tools)
        data = dict({
            "title": "Tool is updated",
            "subTitle": "Tool Info: {}".format(json.dumps(req_dict))
        })
        status = 200
    except REST_Exception as e:
        data = dict({
            "title": "Server Error",
            "subTitle": "Logs: {}".format(str(e))
        })
        status = e.status
    return get_response_json(data, status)
Beispiel #9
0
def login_user():
    session.clear()
    try:
        req_dict = json.loads(request.data)
        user = UserService().login_user(req_dict)
        # login succeeded gen session
        session["username"] = user["username"]
        data = dict({
            "title": "Login success",
        })
        status = 200
    except REST_Exception as e:
        data = dict({
            "title": "Server Error",
            "subTitle": "Logs: {}".format(str(e))
        })
        status = e.status
    return get_response_json(data, status)