检查前端是否已登录管理员 [英] Check on frontend if admin is logged in

查看:101
本文介绍了检查前端是否已登录管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个模块,该模块的行为应与内联翻译相同:

I write a module, which should behave in them same manner as inline translation:

如果我是管理员并且已经登录,则可以在前端看到一些特殊信息.但是,如果我不是管理员,那么我什么也看不到.

If I am admin and I am logged in, I can see something special on frontend. But if I am not admin, then I can't see anything.

如何让模块知道前端区域的管理员已登录?

How to let module know that on frontend area admin is logged in?

更新1

为了澄清一些事情,我想描述一下我的模块行为:

To clarify things I want to describe a little bit my modules behaviour:

后端-仅保存为配置一个值的表单.

Backend - form which simply saves to config one value.

前端-观察者,它挂接到事件.在Observer的功能中,我需要检查

Frontend - Observer, which is hooking to an event. In Observer's function I need to check if

当前前端用户已登录adminpanel ,换句话说,正在监视前端的用户是admin .

由于此检查,我想向管理员用户提供一些基于前端更改的功能.

Because with this check I want to provide to admin user some functionality based on frontend changing.

更新2

问题是我在前端进行了以下session($ _ SESSION)转储:

The thing is that I have following session($_SESSION) dump on frontend:

    [core] => Array
    (
        [_session_validator_data] => Array
            (
                [remote_addr] => ...
                [http_via] => 
                [http_x_forwarded_for] => 
                [http_user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
            )

        [session_hosts] => Array
            (
                [...] => 1
            )

        [messages] => Mage_Core_Model_Message_Collection Object
            (
                [_messages:protected] => Array
                    (
                    )

                [_lastAddedMessage:protected] => 
            )

        [just_voted_poll] => 
        [visitor_data] => Array
            (
                [] => 
                [server_addr] => ...
                [remote_addr] => ...
                [http_secure] => 
                [http_host] => ...
                [http_user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
                [http_accept_language] => ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3
                [http_accept_charset] => windows-1251,utf-8;q=0.7,*;q=0.7
                [request_uri] => ...
                [session_id] => bb397df22a3410ccb07e567cb0333985
                [http_referer] => ...
                [first_visit_at] => 2011-12-01 09:17:48
                [is_new_visitor] => 
                [last_visit_at] => 2011-12-01 13:21:38
                [visitor_id] => 1536
                [last_url_id] => 2408
            )

        [last_url] => ...
    )



    [admin] => Array
    (
        [_session_validator_data] => Array
            (
                [remote_addr] => ...
                [http_via] => 
                [http_x_forwarded_for] => 
                [http_user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
            )

        [session_hosts] => Array
            (
                [...] => 1
            )

    )


    [adminhtml] => Array
    (
        [_session_validator_data] => Array
            (
                [remote_addr] => ...
                [http_via] => 
                [http_x_forwarded_for] => 
                [http_user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
            )

        [session_hosts] => Array
            (
                [...] => 1
            )

    )

也许无法从前端访问管理员用户.好吧,我尝试通过Cookies.

Perhaps there is no way to access admin users from frontend. Well I try via Cookies.

推荐答案

我需要在控制器中做到这一点,特别是preDispatch()方法,我认为这是一个明智的用例.

I needed to do this in a controller, specifically the preDispatch() method, which I think is a sensible use case.

// Ensure we're in the admin session namespace for checking the admin user..
Mage::getSingleton('core/session', array('name' => 'adminhtml'))->start();

$admin_logged_in = Mage::getSingleton('admin/session', array('name' => 'adminhtml'))->isLoggedIn();

// ..get back to the original.
Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start();

这篇关于检查前端是否已登录管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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