zend会话表,如何在标准内容旁边保存user_id?

发布于 2024-10-21 09:38:17 字数 308 浏览 2 评论 0原文

我正在使用 http://framework.zend.com/manual/ en/zend.session.savehandler.dbtable.html

问题是,当我删除用户时,我想删除他的会话以便将他注销,但我不这样做知道他的会话是什么...

我找不到将自定义列添加到 zend 会话表选项的方法,以便保存用户的 id

i am using http://framework.zend.com/manual/en/zend.session.savehandler.dbtable.html,

the problem is that when i delete a user i want to delete his session in order to log him out, but i don't know what his session is...

I can't find a way to add a custom column to the zend session table options so that it would save the user's id

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几度春秋 2024-10-28 09:38:17

您必须使用 Zend_Auth。您可以用来

Zend_Auth::getInstance ()->clearIdentity ();

注销用户。

这就是我的 AuthenticationController 的样子:

class Default_AuthenticationController extends Zend_Controller_Action {

    public function init() {
    }

    public function loginAction() {
        if (Zend_Auth::getInstance ()->hasIdentity ()) {
            $this->_redirect ( 'index/index' );
        }

        $request = $this->getRequest ();
        $form = new Default_Form_LoginForm ();

        if ($request->isPost ()) {
            if ($request->getPost ( 'username' ) != "") {

                $username = $request->getPost ( 'username' );
                $password = $request->getPost ( 'password' );

                $authAdapter = $this->getAuthAdapter ();
            $authAdapter->setIdentity ( $username )
                                        ->setCredential ( $password );
            $auth = Zend_Auth::getInstance ();
            $result = $auth->authenticate ( $authAdapter );
            }
        }
        $this->view->form = $form;
    }

    public function logoutAction() {
        Zend_Auth::getInstance ()->clearIdentity ();
        $this->_redirect ( 'index/index' );
    }

    private function getAuthAdapter() {
        $authAdapter = new Zend_Auth_Adapter_DbTable ( 
                           Zend_Db_Table::getDefaultAdapter () );

        $authAdapter->setTableName ( 'users' )
                         ->setIdentityColumn ( 'email' )
                         ->setCredentialColumn ( 'password' )
                         ->setCredentialTreatment ( 'SHA1(CONCAT(?,salt))' );

        return $authAdapter;
    }
}

观看此操作方法,了解更多详细信息。

You have to use Zend_Auth. You can use

Zend_Auth::getInstance ()->clearIdentity ();

to log a user out.

This is how my AuthenticationController looks like:

class Default_AuthenticationController extends Zend_Controller_Action {

    public function init() {
    }

    public function loginAction() {
        if (Zend_Auth::getInstance ()->hasIdentity ()) {
            $this->_redirect ( 'index/index' );
        }

        $request = $this->getRequest ();
        $form = new Default_Form_LoginForm ();

        if ($request->isPost ()) {
            if ($request->getPost ( 'username' ) != "") {

                $username = $request->getPost ( 'username' );
                $password = $request->getPost ( 'password' );

                $authAdapter = $this->getAuthAdapter ();
            $authAdapter->setIdentity ( $username )
                                        ->setCredential ( $password );
            $auth = Zend_Auth::getInstance ();
            $result = $auth->authenticate ( $authAdapter );
            }
        }
        $this->view->form = $form;
    }

    public function logoutAction() {
        Zend_Auth::getInstance ()->clearIdentity ();
        $this->_redirect ( 'index/index' );
    }

    private function getAuthAdapter() {
        $authAdapter = new Zend_Auth_Adapter_DbTable ( 
                           Zend_Db_Table::getDefaultAdapter () );

        $authAdapter->setTableName ( 'users' )
                         ->setIdentityColumn ( 'email' )
                         ->setCredentialColumn ( 'password' )
                         ->setCredentialTreatment ( 'SHA1(CONCAT(?,salt))' );

        return $authAdapter;
    }
}

Watch this HOW TO for more detailed information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文