Question

This is the most frustrating ever. It is nearly impossible to find errors when all you get is a white screen!!!

This code is used on other projects and it works fine there so syntactically, it is correct. But SOMETHING must be wrong in the configuration...

Here is the code:

protected function _process($values)
{
    // Get our authentication adapter and check credentials
    $adapter = $this->_getAuthAdapter();
    $adapter->setIdentity($values['username']);
    $adapter->setCredential($values['password']);

    $auth = Zend_Auth::getInstance();
    $result = $auth->authenticate($adapter);

    if ($result->isValid()) {
        $user = $adapter->getResultRowObject();
        $auth->getStorage()->write($user);
        return true;
    }
    return false;
}

protected function _getAuthAdapter()
{
    $dbAdapter = Zend_Db_Table::getDefaultAdapter();
    $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
    $authAdapter->setTableName('Users')
                ->setIdentityColumn('username')
                ->setCredentialColumn('password')
                ->setCredentialTreatment('md5(?)');
    return $authAdapter;
}

This is in my auth controller and gets called after I set up the adapter, etc. If I put a die("foo"); right before the $result line, I see it. If I put it right after the $result line, I get a WSOD and the system stops. I know there is not enough here for anyone to debug my code but I was hoping someone else had had this problem and could give me a hint as to what to try to fix this??? I have double checked the database, the column names, etc. I need to know what kinds of things may make the line:

$result = $auth->authenticate($adapter);

result in a white screen of death??? Any ideas? I have all error display turned on in application.ini.

I am running Zend 1.11.12 on this server. Does that make a difference? The server where it is working is running is running 1.12.0-9

Thanks for any ideas you might have.

EDIT::: I added code for my _getAuthAdapter.

Was it helpful?

Solution

Enable the error reporting for your app. Set all error reporting to 1 in your configs/application.ini file -

   phpSettings.display_startup_errors = 1
   phpSettings.display_errors = 1
   resources.frontController.params.displayExceptions = 1

Also, instead of returning true or false, try to print a message, or redirect to a different page to know.

Try a var_dump on the $adapter to see the resulting object.

OTHER TIPS

I've never used Zend_Auth to authenticate. You should be able to do that with your adapter. (assuming your $adapter is an instance of Zend_Auth_Adapter_DbTable for example)

$adapter = $this->_getAuthAdapter();

// this will tell you if there's something wrong with your adapter
if (!($adapter instanceof Zend_Auth_Adapter_DbTable)) {
    throw new Exception('invalid adapter');
}

$adapter->setIdentity($values['username']);
$adapter->setCredential($values['password']);

$result = $adapter->authenticate();
if ($result->isValid()) {

}

I tried like below,

  public function loginAction() {
        $this->_helper->layout->disableLayout();
        $users = new Application_Model_DbTable_Admin();
        $this->_redirector = $this->_helper->getHelper('Redirector');
        $form = new Application_Form_LoginForm();
        $this->view->form = $form;

        if ($this->getRequest()->isPost()) {
            if ($form->isValid($_POST)) {
                $consumer = new Zend_OpenId_Consumer();
                $username = $this->_request->getPost('username');
                $password = $this->_request->getPost('password');

                if ($username <> '' && $password <> '') {
                    $auth = Zend_Auth::getInstance();
                    $authAdapter = new Zend_Auth_Adapter_DbTable($users->getAdapter(), 'admin');
                    $authAdapter->setIdentityColumn('username')
                            ->setCredentialColumn('password');
                    $authAdapter->setIdentity($username)
                            ->setCredential(md5($password));
                    $result = $auth->authenticate($authAdapter);

                    if ($result->isValid()) {
                        $storage = new Zend_Auth_Storage_Session();
                        $storage->write($authAdapter->getResultRowObject());
                        $this->_auth_user = $auth->getStorage()->read();
                        $this->_redirect('admin/index/');
                    }
                    else
                        $this->view->errorMessage = "Invalid username or password. Please try again.";
                }
                else
                    $this->view->errorMessage = "Username or password should not be empty!!!.";
            }
        }
    }

If your Adapter doesn't work try it:

public function _getAuthAdapter() {
        $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
        $authAdapter->setTableName('table_name')
                ->setIdentityColumn('user_name')
                ->setCredentialColumn('password');
        return $authAdapter;
}

And in application.ini

resources.db.isDefaultTableAdapter = true
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top