We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38720
    • 23 Posts
    Hi,
    I have a form that allows users to add resources to the tree, unpublished, from the front-end.
    I'm using

    ...
    $fields['type']='document';
    $fields['contentType']='text/html';
    $fields['pagetitle']="$name";
    $fields['longtitle']="$name";
    $fields['description']='';
    $fields['alias']="$alias";
    ...

    $response = $modx->runProcessor('resource/create', $fields);

    But I'm getting Permission_Denied.

    Is it because the user needs to be logged in? If so, is there a way to bypass needing the user to login? Or could I auto-login a preset user so that the resource can be created? Thanks for any suggestion.

      • 22303 MODX Staff
      • 10,725 Posts
      The user will need to have the appropriate Administrator policy on the context to allow them to take those actions from the context the request is made from. In this case, the web Context would need the appropriate policy for the user taking the action.
        • 38720
        • 23 Posts
        Thanks!

        I'm using this (assuming the user has web context access and permission to create resource):

        $_POST['username'] = 'user';
        $_POST['password'] = 'pass';
        $_POST['service'] = 'login';
        $_REQUEST['service'] = 'login';
        $modx->runSnippet('Login', $scriptProperties);

        Then create/resource using runProcess....

        $modx->runSnippet('Logout');


        Does this look okay or am I going about the wrong way? [ed. note: javster last edited this post 13 years, 8 months ago.]
          • 22303 MODX Staff
          • 10,725 Posts
          You can't login that way, no. The user would already need to be logged in to the web context and have those policies available in the web context. If your intention is to allow anonymous users to do this, you might be better off creating a custom Snippet to make this possible without providing all anonymous users with permission to execute various core processors.
            • 38720
            • 23 Posts
            Thanks for the clarification.

            Quote from: opengeek at Feb 18, 2013, 05:00 PM
            You can't login that way, no. The user would already need to be logged in to the web context and have those policies available in the web context. If your intention is to allow anonymous users to do this, you might be better off creating a custom Snippet to make this possible without providing all anonymous users with permission to execute various core processors.