cookies - Joomla 3.6 身份验证和登录

标签 cookies authentication joomla token


我很难清楚地了解 Joomla(我使用的是 3.6.x 版)身份验证和登录。
我已经看到许多关于如何从外部来源“登录”Joomla 站点的方法和片段(这正是我感兴趣的地方)。
但是我在测试和测试(以及更多测试)之后看到的是,在一天结束时,您根本就没有登录。
您可能能够验证尝试登录的用户是否是有效的注册用户,并且能够检索他的姓名、电子邮件、电话和诸如此类等等,但在 Joomla 后端,该用户仍未登录。< br/> 我在管理员面板中创建了一个全新的用户(它显示用户从未访问过该站点),我用外部 PHP 编写了登录脚本,我对新用户进行了十几次“身份验证”,当我回到后端时,用户仍然从未去过那里。一次都没有。
我想,这也意味着我无法检索“事件”用户列表,因为 Joomla 无法将他们视为已登录用户。

所以我想要实现的是用户能够从 Joomla 站点外部登录并能够知道他们是否登录。所以我可以获得他们的列表并为他们分配任务。
我想这与 token 和cookie有关。但是无论我朝那个方向搜索多少,我都找不到任何例子来启发我。
非常感谢任何帮助(特别是“脚本”帮助)。
谢谢。

<?php
        if (version_compare(PHP_VERSION, '5.3.1', '<')) {
            die('Your host needs to use PHP 5.3.1 or higher to run this version of Joomla!');
        }

        define('_JEXEC', 1);

        if (file_exists(__DIR__ . '/defines.php')) {
            include_once __DIR__ . '/defines.php';
        }

        if (!defined('_JDEFINES')) {
            define('JPATH_BASE', __DIR__);
            require_once JPATH_BASE . '/includes/defines.php';
        }

        require_once JPATH_BASE . '/includes/framework.php';

        $app = JFactory::getApplication('site');
        $app->initialise();

        require_once (JPATH_BASE .'/libraries/joomla/factory.php');


        $credentials['username'] = $_GET["usrname"];
        $credentials['password'] = $_GET["passwd"];

        $db    = JFactory::getDbo();
        $query = $db->getQuery(true)
            ->select('id, password')
            ->from('#__users')
            ->where('username=' . $db->quote($credentials['username']));

        $db->setQuery($query);
        $result = $db->loadObject();

        if ($result) {
            $match = JUserHelper::verifyPassword($credentials['password'], $result->password, $result->id);

            if ($match === true) {
                $user = JUser::getInstance($result->id);
                $session =& JFactory::getSession();

                echo "<p>Your name is {$user->name}, your email is {$user->email}, and your username is {$user->username}</p>";

                $session->set('userid', $user->id);

                if ($user->guest) {
                    echo 'SORRY, NO LOGIN YET...';
                } else {
                    echo 'user is LOGGED IN !';
                }

            } else {
                die('Invalid password');
            }
        } else {
            die('Cound not find user in the database');
        }
    ?>

最佳答案

Joomla 登录在身份验证插件中处理,通过编写并启用您自己的插件,您可以绕过 token 验证并允许通过简单的获取请求登录。

请记住 Joomla!将管理员前端 session 分开(您可以登录到管理员,并以访客身份浏览站点)。此外,用户需要具有经理、管理员或 super 用户组成员身份才能登录后端。

管理员

管理员登录的常见用例是运行后台脚本。 为了绕过后端的 Joomla 身份验证,请检查/cli 文件夹,因为它包含一些示例。

前端

前端登录的用例要广泛得多:服务器到服务器的通信、应用程序身份验证、单点登录等。

执行前端身份验证的最佳做法是构建您自己的身份验证插件。身份验证将由 onUserAuthenticate() 函数实现。查看 /plugins/authentication/joomla/ 插件作为示例。

如果你需要额外的数据来让认证插件发挥它的魔力(例如远程 token /api key 来使用远程服务进行认证)你可能想要检查用户插件组,例如 /plugins/user/profile 插件。

验证上次登录日期/时间

前端方法应该会自动工作,在管理员控制面板中显示用户已登录。

但是,如果您使用 CLI 方法登录到管理员,这可能无法正常工作,具体取决于您执行登录的方式。

关于cookies - Joomla 3.6 身份验证和登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42603058/

相关文章:

.net - 在 .NET 2.0 中使用 "Remember Me"功能进行身份验证

json - 通过json发送expressjs cookie

重定向后未设置 Django : request. 用户

python - 使用 python-ldap 对 Active Directory 进行身份验证总是返回 (97, [])

java - Spring:无法将 SameSite cookie 设置为 None

javascript - cookie 的设置值 - 名称中的冒号

java - 检查管理员登录( HashMap )

php - Joomla 3.2.1密码加密

javascript - 如何跟踪 javascript 文件请求的来源

mysql - 需要找到mysql行之间的共同元素