public function test_login_user() { global $USER; $this->resetAfterTest(); $user = $this->getDataGenerator()->create_user(); $this->setUser(0); $this->assertEquals(0, $USER->id); @\core\session\manager::login_user($user); // Ignore header error messages. $this->assertEquals($user->id, $USER->id); }
/** * Call to complete the user login process after authenticate_user_login() * has succeeded. It will setup the $USER variable and other required bits * and pieces. * * NOTE: * - It will NOT log anything -- up to the caller to decide what to log. * - this function does not set any cookies any more! * * @param stdClass $user * @return stdClass A {@link $USER} object - BC only, do not use */ function complete_user_login($user) { global $CFG, $USER, $SESSION; \core\session\manager::login_user($user); // Reload preferences from DB. unset($USER->preference); check_user_preferences_loaded($USER); // Update login times. update_user_login_times(); // Extra session prefs init. set_login_session_preferences(); // Trigger login event. $event = \core\event\user_loggedin::create(array('userid' => $USER->id, 'objectid' => $USER->id, 'other' => array('username' => $USER->username))); $event->trigger(); if (isguestuser()) { // No need to continue when user is THE guest. return $USER; } if (CLI_SCRIPT) { // We can redirect to password change URL only in browser. return $USER; } // Select password change url. $userauth = get_auth_plugin($USER->auth); // Check whether the user should be changing password. if (get_user_preferences('auth_forcepasswordchange', false)) { if ($userauth->can_change_password()) { if ($changeurl = $userauth->change_password_url()) { redirect($changeurl); } else { $SESSION->wantsurl = core_login_get_return_url(); redirect($CFG->httpswwwroot . '/login/change_password.php'); } } else { print_error('nopasswordchangeforced', 'auth'); } } return $USER; }
public function test_login_user() { global $USER; $this->resetAfterTest(); $this->assertEquals(0, $USER->id); $user = $this->getDataGenerator()->create_user(); @\core\session\manager::login_user($user); // Ignore header error messages. $this->assertEquals($user->id, $USER->id); $this->assertObjectNotHasAttribute('description', $user); $this->assertObjectNotHasAttribute('password', $user); $this->assertSame($user, $GLOBALS['USER']); $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); $this->assertSame($GLOBALS['USER'], $USER); }