Пример #1
0
def select_nodenet_from_console(nodenet_uid):
    user_id, permissions, token = get_request_data()
    result, uid = runtime.load_nodenet(nodenet_uid)
    if not result:
        return template("error", msg="Could not select nodenet")
    response.set_cookie("selected_nodenet", nodenet_uid + "/", path="/")
    redirect("/")
Пример #2
0
def delete_nodenet_from_console(nodenet_uid):
    user_id, permissions, token = get_request_data()
    if "manage nodenets" in permissions:
        runtime.delete_nodenet(nodenet_uid)
        response.set_cookie('notification', '{"msg":"Nodenet deleted", "status":"success"}', path='/')
        redirect('/nodenet_mgt')
    return template("error", msg="Insufficient rights to access nodenet console")
Пример #3
0
def signup_submit():
    params = dict((key, request.forms.getunicode(key)) for key in request.forms)
    user_id, permissions, token = get_request_data()
    userid = params['userid']
    password = params['password']
    role = params.get('permissions')
    firstuser = not usermanager.users
    (success, result) = micropsi_core.tools.check_for_url_proof_id(userid, existing_ids=usermanager.users.keys())
    if success:
        # check if permissions in form are consistent with internal permissions
        if ((role == "Administrator" and ("create admin" in permissions or not usermanager.users)) or
            (role == "Full" and "create full" in permissions) or
            (role == "Restricted" and "create restricted" in permissions)):
            if usermanager.create_user(userid, password, role, uid=micropsi_core.tools.generate_uid()):
                # log in new user
                token = usermanager.start_session(userid, password, params.get("keep_logged_in"))
                response.set_cookie("token", token)
                # redirect to start page
                return dict(redirect='/')
            else:
                return dict(status="error", msg="User creation failed for an obscure internal reason.")
        else:
            return dict(status="error", msg="Permission inconsistency during user creation.")
    else:
        # something wrong with the user id, retry
        return template("signup", version=VERSION, userid=userid, password=password, userid_error=result,
            title="Create a new user for the %s server" % APPTITLE, first_user=firstuser,
            user_id=user_id, permissions=permissions, cookie_warning=(token is None))
Пример #4
0
def login_submit():
    params = dict((key, request.forms.getunicode(key)) for key in request.forms)
    user_id = params['userid']
    password = params['password']
    # log in new user
    token = usermanager.start_session(user_id, password, params.get("keep_logged_in"))
    if token:
        response.set_cookie("token", token)
        # redirect to start page
        return dict(redirect="/")
    else:
        # login failed, retry
        if user_id in usermanager.users:
            return template("login", version=VERSION, userid=user_id, password=password,
                title="Log in to the %s server" % APPTITLE,
                password_error="Re-enter the password",
                login_error="User name and password do not match",
                cookie_warning=(token is None),
                permissions=usermanager.get_permissions_for_session_token(token))
        else:
            return template("login", version=VERSION, userid=user_id, password=password,
                title="Log in to the %s server" % APPTITLE,
                userid_error="Re-enter the user name",
                login_error="User unknown",
                cookie_warning=(token is None),
                permissions=usermanager.get_permissions_for_session_token(token))
Пример #5
0
def _add_world_list(template_name, **params):
    worlds = runtime.get_available_worlds()
    if request.query.get('select_world') and request.query.get('select_world') in worlds:
        current_world = request.query.get('select_world')
        response.set_cookie('selected_world', current_world)
    else:
        current_world = request.get_cookie('selected_world')
    world_type = ""
    world_assets = {}
    world_template = ""
    if current_world:
        world_obj = runtime.load_world(current_world)
        world_type = world_obj.__class__.__name__
        if hasattr(world_obj, 'assets'):
            world_assets = world_obj.assets
        if 'template' in world_assets:
            import inspect
            basedir = os.path.dirname(inspect.getfile(world_obj.__class__))
            with open(os.path.join(basedir, world_assets['template'])) as fp:
                world_template = template(fp.read(), world_assets=world_assets)
    return template(template_name, current=current_world,
        mine=dict((uid, worlds[uid]) for uid in worlds if worlds[uid].get('owner') == params['user_id']),
        others=dict((uid, worlds[uid]) for uid in worlds if worlds[uid].get('owner') != params['user_id']),
        world_type=world_type,
        world_assets=world_assets,
        world_template=world_template,
        **params)
Пример #6
0
def save_all_nodenets():
    user_id, permissions, token = get_request_data()
    if "manage nodenets" in permissions:
        for uid in runtime.nodenets:
            runtime.save_nodenet(uid)
        response.set_cookie('notification', '{"msg":"All nodenets saved", "status":"success"}', path='/')
        redirect('/nodenet_mgt')
    return template("error", msg="Insufficient rights to access nodenet console")
Пример #7
0
def nodenet_mgt():
    user_id, permissions, token = get_request_data()
    if "manage nodenets" in permissions:
        notification = None
        if request.get_cookie('notification'):
            notification = json.loads(request.get_cookie('notification'))
            response.set_cookie('notification', '', path='/')
        return template("nodenet_mgt", version=VERSION, permissions=permissions,
            user_id=user_id,
            nodenet_list=runtime.get_available_nodenets(), notification=notification)
    return template("error", msg="Insufficient rights to access nodenet console")
Пример #8
0
def _add_world_list(template_name, **params):
    worlds = runtime.get_available_worlds()
    if request.query.get('select_world') and request.query.get('select_world') in worlds:
        current_world = request.query.get('select_world')
        response.set_cookie('selected_world', current_world)
    else:
        current_world = request.get_cookie('selected_world')
    if current_world in worlds and hasattr(worlds[current_world], 'assets'):
        world_assets = worlds[current_world].assets
    else:
        world_assets = {}
    return template(template_name, current=current_world,
        mine=dict((uid, worlds[uid]) for uid in worlds if worlds[uid].owner == params['user_id']),
        others=dict((uid, worlds[uid]) for uid in worlds if worlds[uid].owner != params['user_id']),
        world_assets=world_assets, **params)