0

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

4

1 回答 1

0

你必须使用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;
    }
}

观看此HOW TO以获取更多详细信息。

于 2011-03-25T13:17:30.307 回答