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.
Options

[SOLVED] php function to add user?

caerostriscaerostris ✭✭
edited February 2011 in Vanilla 2.0 - 2.8
Hey there!

Im currently writing a plugin to support authentication via an OpenLDAP server.
I've done a phpscript which checks if a user could be found as ldap user, and if its password correct, and another function to determine the groups he's a member of.

So im currently trying to integrate it into vanilla2, but i've got one problem:
I need to create the user in the mysql database which vanilla2 uses (roles and so on...), but i cant find a function in the sourcecode of vanilla, which allows me to create a useraccount...

Im looking for a function like this:
$Gdn::User->UserAdd($password, $username, $email, $groups);

So that my plugin is able to add users...

Anyone has an idea?
Or maybe there is even someone familiar with ldap authentication in php, i could need some help on how it works at all!
(I've got a concept which would get it working, but im not sure if its really the best way to realise it...)


Regards, Caerostris

Comments

  • Options
    caerostriscaerostris ✭✭
    edited February 2011
    Whew!

    After (felt) hours of work, i was able to find out how to create a user!
    It was a little bit difficult since there is no function in vanilla2 like $UserModel->CreateNew or so...

    If you're intrested, here is my code:

    $UserData['Name'] = "testxxx"; $UserData['Password'] = "testpw"; $UserData['Email'] = "no@email.com"; $UserData['Gender'] = "m"; $UserData['HourOffset'] = "0"; $UserData['DateOfBirth'] = ""; $UserData['CountNotifications'] = "0"; //$UserData['Attributes'] = Gdn_Format::Serialize($Attributes); // Save the user. $UserModel = new UserModel(); $UserID = $UserModel->Save($UserData, array('ActivityType' => 'Join', 'CheckExisting' => TRUE)); // Add the user to the default role(s). if ($UserID) { $UserModel->SaveRoles($UserID, C('Garden.Registration.DefaultRoles')); }



    This is working...


    Regards, Caerostris
This discussion has been closed.