0
votes

Fairly new to Zend Framework 1.11 with Doctrine 2.

I have successfully created a login etc using Doctrine.

My current problem though is that the Zend_Auth instance works fine when I stay within the controller that the log in is within.

If I try determine the state of Zend_Auth::getInstance->HasIdentity() in any other controller it returns blank.

If I then go back to any page residing within the controller containing the login/authentication hasIdentity works fine.

I have even tried writing to the storage but this provides no joy.

My auth code is as follows which is the action called after clicking Login (Within MembersareaController)

public function authAction()
{
    $this->_helper->viewRenderer->setNoRender(true);

    $loginForm = new Application_Model_Login();

    if($this->getRequest()->isPost()){
        $usr = "";
        $pwd = "";
        $KeepLoggedIn = false;
        $message = "";

        $usr = $this->_getParam('username'); 
        $pwd = $this->_getParam('password');
        $pwdMd5 = md5($pwd);

        if($usr !== "" && $pwd !== ""){

            $GDSAdaptor = new ZC_Auth_Adapter($usr, $pwdMd5);

            $result = \Zend_Auth::getInstance()->authenticate($GDSAdaptor);

            if(\Zend_Auth::getInstance()->hasIdentity()){
                $this->flashMessenger->addMessage(LOGIN_SUCCESS);
                $this->_redirect('/membersarea/index');
            }else{
                $this->flashMessenger->addMessage(LOGIN_INVALID);
            }
        }else{
            $this->flashMessenger->addMessage(LOGIN_MISSING_FORMVAL);
            $this->_redirect('/membersarea/login');
        }
    }

Trying to seeing a person is logged in on the IndexController with the following code produces no results. hasIdentity returns a blank value.

public function indexAction()
{

    if(Zend_Auth::getInstance()->hasIdentity())
    {
        $msg = "hasIdentity: YES";
    }else{
        $msg = "hasIdentity: NO";
    }

    $this->view->msg = $msg;
}
1
Are you sure the cookie for your PHP session is set to the proper domain? I think you should verify using firebugRageZ
Hi. Thanks for your reply. I've compared the cookie info using Firebug between the two and the cookie info is identical.John Cogan
I have noticed that there are two seperate cookies for the domain with differing PHPSESSION ids and the paths are different. One has the path set to '/membersarea' which is the controller with the auth stuff on and the second is set to '/' which is the homepage.John Cogan

1 Answers

0
votes

Zend_Session::rememberMe(); in the bootstrap solved this issue