MDL-81525 core_user: Move after_complete_login to correct NS

This commit is contained in:
Andrew Nicols
2024-04-15 08:53:35 +08:00
parent d706265b8e
commit ffc51ab3fd
4 changed files with 25 additions and 25 deletions
@@ -14,23 +14,26 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_mobile\local\hooks\user;
namespace tool_mobile;
use core\session\utility\cookie_helper;
/**
* Handles mobile app launches when a third-party auth plugin did not properly set $SESSION->wantsurl.
* Allows plugins to add any elements to the footer.
*
* @package tool_mobile
* @copyright 2024 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class after_complete_login {
class hook_callbacks {
/**
* Callback to recover $SESSION->wantsurl.
*
* @param \core\hook\user\after_complete_login $hook
* @param \core_user\hook\after_login_completed $hook
*/
public static function callback(\core\hook\user\after_complete_login $hook): void {
public static function after_login_completed(
\core_user\hook\after_login_completed $hook,
): void {
global $SESSION, $CFG;
// Check if the user is doing a mobile app launch, if that's the case, ensure $SESSION->wantsurl is correctly set.
@@ -43,7 +46,10 @@ class after_complete_login {
// Set Partitioned and Secure attributes to the MoodleSession cookie if the user is using the Moodle app.
if (\core_useragent::is_moodle_app()) {
cookie_helper::add_attributes_to_cookie_response_header('MoodleSession'.$CFG->sessioncookie, ['Secure', 'Partitioned']);
cookie_helper::add_attributes_to_cookie_response_header(
'MoodleSession' . $CFG->sessioncookie,
['Secure', 'Partitioned'],
);
}
}
}
+2 -2
View File
@@ -26,8 +26,8 @@ defined('MOODLE_INTERNAL') || die();
$callbacks = [
[
'hook' => core\hook\user\after_complete_login::class,
'callback' => 'tool_mobile\local\hooks\user\after_complete_login::callback',
'hook' => \core_user\hook\after_login_completed::class,
'callback' => \tool_mobile\hook_callbacks::class . '::after_login_completed',
'priority' => 500,
],
[
+1 -1
View File
@@ -4588,7 +4588,7 @@ function complete_user_login($user, array $extrauserinfo = []) {
$event->trigger();
// Allow plugins to callback as soon possible after user has completed login.
$hook = new \core\hook\user\after_complete_login();
$hook = new \core_user\hook\after_login_completed();
\core\hook\manager::get_instance()->dispatch($hook);
// Check if the user is using a new browser or session (a new MoodleSession cookie is set in that case).
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\hook\user;
namespace core_user\hook;
use core\hook\described_hook;
use core\hook\stoppable_trait;
@@ -22,29 +22,23 @@ use core\hook\stoppable_trait;
/**
* Allow plugins to callback as soon possible after user has completed login.
*
* @package core
* @package core_user
* @copyright 2024 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class after_complete_login implements described_hook,
\Psr\EventDispatcher\StoppableEventInterface {
class after_login_completed implements
described_hook,
\Psr\EventDispatcher\StoppableEventInterface
{
use stoppable_trait;
/**
* Describes the hook purpose.
*
* @return string
*/
public static function get_hook_description(): string {
return 'Allow plugins to callback as soon possible after user has completed login.';
}
/**
* List of tags that describe this hook.
*
* @return string[]
*/
public static function get_hook_tags(): array {
return ['login'];
return [
'login',
'user',
];
}
}