Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Plugin working when accessed from browser, but not from PHP. (RoleModel::roles() issue)

I'm guessing I'm missing something obvious, or going about this the wrong way. What I'm trying to accomplish is that when somebody creates an account for my site, that site's registration PHP script also calls a custom Vanilla plugin (UserCreator) which, in turn, sets up a forum account with the same username, password and e-mail address.

The plugin I made works fine when I access it at http://localhost/path/to/forum/plugin/usercreator?username=bob/. It creates the account and sets up its permissions, or throws an error if it failed.

To call this through PHP, I wanted to avoid having to build and install separate HTTP extensions, so I figured I might emulate it using file_get_contents("http://".$_SERVER['SERVER_NAME']."/path/to/forum/plugin/usercreator?username=bob/");. This, however, gives me the following error: Call to undefined method RoleModel::roles().

Does anyone know what could be causing this, or know of a better way to go about it?

Thanks,
Patrick

Comments

  • Small update: The error now appears when accessing the plugin from the browser as well, despite me having changed anything. So... yay for uniformity, I guess?

  • R_JR_J Admin

    Maybe that discussion could give you a hint: http://vanillaforums.org/discussion/24362/how-do-i-post-a-comment-using-an-external-php-script-in-vanilla

    I'm quite sure I've read about something like that before. You can try and use Google to find some answers: https://www.google.de/#q=site:vanillaforums.org+use+vanilla+external

  • Oh man, seems my Google-fu really failed me there; thanks for helping me get on track!

    For those reading this in the future, here's how I solved my issue:

    • Call "path/to/forum/plugin/usercreator/" from PHP using curl, with POST-values if needed.
    • Inside the plugin's Controller_Index($Sender) method:
      • Create an assosciative array with all needed userdata properties (i.e.: $data['Name'] = $_POST['username']).
      • Call Gdn::UserModel()->InsertForBasic($data, FALSE, array("ValidateEmail" => TRUE, "NoConfirmMail" => TRUE)); //(userdata, useCaptcha, options).
      • If the user was added succesfully, InsertForBasic() will return that user's ID.

    Thanks for the help! Cheers!

Sign In or Register to comment.