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

Charles
  • 50,943
  • 13
  • 104
  • 142
max4ever
  • 11,909
  • 13
  • 77
  • 115

1 Answers1

0

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.

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
  • i believe i explained myself bad, if i am logged in as admin and i delete another user, i want to log out that user, not myself – max4ever Mar 25 '11 at 15:27
  • then you have to use database driven session storage, so you can remove sessions http://stackoverflow.com/questions/854092/zend-storing-session-data-in-a-database. map session and user id to get logged in users and log them out – DarkLeafyGreen Mar 25 '11 at 16:10