Joomla注销并显示消息 [英] Joomla logout with message

查看:63
本文介绍了Joomla注销并显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改

令牌拦截器"系统插件

'Token Interceptor' system plugin

joomunited.com

原始插件会在使用register_shutdown_function遇到无效令牌错误时重定向.

The original plugin redirects on encountering an invalid token error using register_shutdown_function.

我正在尝试将其发送到:

I'm trying to get it to:

  1. 如果用户已登录,请注销该用户
  2. 使用无效的令牌消息重定向到登录页面

代码:

$app = JFactory::getApplication();
if (!JFactory::getUser()->guest)
{
    $app->logout();
}
$app->redirect('/index.php', JText::_('JINVALID_TOKEN'), 'warning');

我可以成功注销用户并重定向到登录页面,但不会显示错误消息.

I can successfully log the user out and redirect to the login page but the error message is not being displayed.

注销用户后如何保留消息?

How can I retain the message after logging the user out?

我也尝试过:

$app->enqueueMessage(JText::_('JINVALID_TOKEN'), 'warning');

但是那也不起作用...

but that didn't work either...

推荐答案

我想到的解决方案是Alonzo Turner的第二篇文章的变体

The solution I came up with was a variation of Alonzo Turner's 2nd post here.

该插件使用在URL中传递的参数重定向到登录页面.然后,onAfterInitialise事件将查找此参数,并在找到该消息时显示一条消息.

The plugin redirects to the login page with a parameter passed in the url. The onAfterInitialise event then looks for this parameter and displays a message if it's found.

class PlgSystemTokeninterceptor extends JPlugin
{

    public function __construct(&$subject, $config = array())
    {
        parent::__construct($subject, $config);
        $app = JFactory::getApplication();

        if (($app->isSite() && $this->params->get('use_frontend')) || ($app->isAdmin() && $this->params->get('use_backend'))) 
        {
            register_shutdown_function(array($this,'redirectToLogin'));
        }

    }

    public function redirectToLogin()
    {
        $content = ob_get_contents();

        if($content == JText::_('JINVALID_TOKEN') || $content == 'Invalid Token')
        {
            $app = JFactory::getApplication();

            if (!JFactory::getUser()->guest)
            {
                $app->logout();
            }

            $app->redirect(JURI::base().'index.php?invalid_token=true');

            return false;   
        }
    }

    function onAfterInitialise()
    {
        $app = JFactory::getApplication();
        $invalid_token = $app->input->get('invalid_token', 'false');

        if ($invalid_token == 'true')
        {
            $app->enqueueMessage(JText::_('JINVALID_TOKEN'), 'warning');
        }

        return true;
    }

}

这篇关于Joomla注销并显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆