Login after signup

Login after signup

by Dominik Stuerzer -
Number of replies: 0

I'm trying to make my first Moodle auth extension where I want to confirm and login users directly after signup.

I've changed the user_signup function in the "email" auth plugin like this:

\core\event\user_created::create_from_userid($user->id)->trigger();

$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));

$user = get_complete_user_data('username', $username);
$DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
$DB->set_field("user", "lastlogin", 0, array("id"=>$user->id));
update_user_login_times($user);

complete_user_login($user);
redirect("$CFG->wwwroot/enrol/index.php?id=2");

It works so far as the user gets signed up and confirmed. But as for the login I get the following error:

core\session\manager::login_user() must be an instance of stdClass, boolean given

I have Moodle 2.7.2 on an Ubuntu VM.

I might be acting stupid here, but I don't know how I could login the new user here. Any help would be very much apprechiated. Thanks!


Average of ratings: -