I am trying to create an authentication plugin, but I am having problems when the user does not exist in the moodle database. Therefore I am trying to find a way to manually create a user.
I tried:
$user = new StdClass();
$user->username = $ucUser;
$user->auth = 'ucauth';
$user->firstname = "First";
$user->lastname = "Last";
$user->id = $DB->insert_record('user', $user);
But it didn't work... I got an insert error. What else do I need in the $user
object?
User object should have the following values:
$user = new StdClass();
$user->auth = 'manual';
$user->confirmed = 1;
$user->mnethostid = 1;
$user->email = "email";
$user->username = "username";
$user->password = md5('password');
$user->lastname = "lastname";
$user->firstname = "firstname";
$user->id = $DB->insert_record('user', $user);
Please try this.
Well, I recommend you to use authenticate_user_login($username, null)
this is going to give you an empty user, wich you can complete later on in the proccess. Then you can use complete_user_login($user);
and if you want to send the user to the edit page something like
if (user_not_fully_set_up($USER)) {
$urltogo = $CFG->wwwroot.'/user/edit.php';
}else{
$urltogo = $CFG->wwwroot.'/';
}
redirect($urltogo);
I don't know exactly what are you trying to achieve. But I've made a plugin to connect with an external web service and it took me a while to figure out how to do it properly. I'm able to help you with anything you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With